Commit a0d1f22656b59a01ba64dced0b1e6667a6ed8ccd

Authored by 张建亮
1 parent 9e640847

创建baseAdapter,baseFragment

app/build.gradle
@@ -35,6 +35,7 @@ android { @@ -35,6 +35,7 @@ android {
35 versionName "3.0.0" 35 versionName "3.0.0"
36 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 36 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
37 37
  38 +
38 ndk { 39 ndk {
39 moduleName "gold" 40 moduleName "gold"
40 ldLibs "log", "z", "m" 41 ldLibs "log", "z", "m"
app/src/main/java/com/cnlive/goldenline/baseadpter/BaseBindingAdapter.java 0 → 100644
  1 +package com.cnlive.goldenline.baseadpter;
  2 +
  3 +import android.content.Context;
  4 +import android.databinding.DataBindingUtil;
  5 +import android.databinding.ViewDataBinding;
  6 +import android.support.v7.widget.RecyclerView;
  7 +import android.view.LayoutInflater;
  8 +import android.view.ViewGroup;
  9 +
  10 +
  11 +import com.cnlive.goldenline.BR;
  12 +
  13 +import java.util.ArrayList;
  14 +import java.util.List;
  15 +
  16 +
  17 +
  18 +/**
  19 + * Created by ZJL on 2017/5/14.
  20 + */
  21 +
  22 +public class BaseBindingAdapter<D, B extends ViewDataBinding> extends RecyclerView.Adapter<BaseBindingVH<B>> {
  23 + protected Context mContext;
  24 + protected int mLayoutId;
  25 + protected List<D> mDatas;
  26 + protected LayoutInflater mInfalter;
  27 + //用于设置Item的事件Presenter
  28 + protected Object ItemPresenter;
  29 +
  30 + public BaseBindingAdapter(Context mContext, List mDatas, int mLayoutId) {
  31 + this.mContext = mContext;
  32 + this.mLayoutId = mLayoutId;
  33 + this.mDatas = mDatas;
  34 + this.mInfalter = LayoutInflater.from(mContext);
  35 + }
  36 +
  37 + public BaseBindingAdapter(Context mContext, List mDatas) {
  38 + this.mContext = mContext;
  39 + this.mDatas = mDatas;
  40 + this.mInfalter = LayoutInflater.from(mContext);
  41 + }
  42 +
  43 + @Override
  44 + public BaseBindingVH<B> onCreateViewHolder(ViewGroup parent, int viewType) {
  45 + BaseBindingVH<B> holder = new BaseBindingVH<B>((B) DataBindingUtil.inflate(mInfalter, mLayoutId, parent, false));
  46 + onCreateViewHolder(holder);
  47 + return holder;
  48 + }
  49 +
  50 + /**
  51 + * 如果需要给Vh设置监听器啥的 可以在这里
  52 + *
  53 + * @param holder
  54 + */
  55 + public void onCreateViewHolder(BaseBindingVH<B> holder) {
  56 +
  57 + }
  58 +
  59 + /**
  60 + * 子类除了绑定数据,还要设置监听器等其他操作。
  61 + * 可以重写这个方法,不要删掉super.onBindViewHolder(holder, position);
  62 + *
  63 + * @param holder
  64 + * @param position
  65 + */
  66 + @Override
  67 + public void onBindViewHolder(BaseBindingVH<B> holder, int position) {
  68 + holder.getBinding().setVariable(BR.data, mDatas.get(position));
  69 + holder.getBinding().setVariable(BR.itemP, ItemPresenter);
  70 + holder.getBinding().executePendingBindings();
  71 + }
  72 +
  73 + @Override
  74 + public int getItemCount() {
  75 + return null != mDatas ? mDatas.size() : 0;
  76 + }
  77 +
  78 + public Object getItemPresenter() {
  79 + return ItemPresenter;
  80 + }
  81 +
  82 + /**
  83 + * 用于设置Item的事件Presenter
  84 + *
  85 + * @param itemPresenter
  86 + * @return
  87 + */
  88 + public BaseBindingAdapter setItemPresenter(Object itemPresenter) {
  89 + ItemPresenter = itemPresenter;
  90 + return this;
  91 + }
  92 +
  93 + /**
  94 + * 刷新数据,初始化数据
  95 + *
  96 + * @param list
  97 + */
  98 + public void setDatas(List<D> list) {
  99 + if (this.mDatas != null) {
  100 + if (null != list) {
  101 + List<D> temp = new ArrayList<D>();
  102 + temp.addAll(list);
  103 + this.mDatas.clear();
  104 + this.mDatas.addAll(temp);
  105 + } else {
  106 + this.mDatas.clear();
  107 + }
  108 + } else {
  109 + this.mDatas = list;
  110 + }
  111 + notifyDataSetChanged();
  112 + }
  113 +
  114 + /**
  115 + * 删除一条数据
  116 + * 会自动定向刷新
  117 + *
  118 + * @param i
  119 + */
  120 + public void remove(int i) {
  121 + if (null != mDatas && mDatas.size() > i && i > -1) {
  122 + mDatas.remove(i);
  123 + notifyItemRemoved(i);
  124 + }
  125 + }
  126 +
  127 + /**
  128 + * 添加一条数据 至队尾
  129 + * 会自动定向刷新
  130 + *
  131 + * @param data
  132 + */
  133 + public void add(D data) {
  134 + if (data != null && mDatas != null) {
  135 + mDatas.add(data);
  136 + notifyItemInserted(mDatas.size());
  137 + }
  138 + }
  139 +
  140 + /**
  141 + * 在指定位置添加一条数据
  142 + * 会自动定向刷新
  143 + * <p>
  144 + * 如果指定位置越界,则添加在队尾
  145 + *
  146 + * @param position
  147 + * @param data
  148 + */
  149 + public void add(int position, D data) {
  150 + if (data != null && mDatas != null) {
  151 + if (mDatas.size() > position && position > -1) {
  152 + mDatas.add(position, data);
  153 + notifyItemInserted(position);
  154 + } else {
  155 + add(data);
  156 + }
  157 + }
  158 + }
  159 +
  160 +
  161 + /**
  162 + * 加载更多数据
  163 + *
  164 + * @param list
  165 + */
  166 + public void addDatas(List<D> list) {
  167 + if (null != list) {
  168 + List<D> temp = new ArrayList<D>();
  169 + temp.addAll(list);
  170 + if (this.mDatas != null) {
  171 + this.mDatas.addAll(temp);
  172 + } else {
  173 + this.mDatas = temp;
  174 + }
  175 + notifyDataSetChanged();
  176 + }
  177 +
  178 + }
  179 +
  180 +
  181 + public List<D> getDatas() {
  182 + return mDatas;
  183 + }
  184 +}
app/src/main/java/com/cnlive/goldenline/baseadpter/BaseBindingVH.java 0 → 100644
  1 +package com.cnlive.goldenline.baseadpter;
  2 +
  3 +import android.databinding.ViewDataBinding;
  4 +import android.support.v7.widget.RecyclerView;
  5 +
  6 +/**
  7 + * Created by ZJL on 2017/5/14.
  8 + */
  9 +
  10 +public class BaseBindingVH<T extends ViewDataBinding> extends RecyclerView.ViewHolder {
  11 + protected final T mBinding;
  12 +
  13 + public BaseBindingVH(T t) {
  14 + super(t.getRoot());
  15 + mBinding = t;
  16 + }
  17 +
  18 + public T getBinding() {
  19 + return mBinding;
  20 + }
  21 +}
app/src/main/java/com/cnlive/goldenline/ui/activity/RegisterActivity.java
@@ -4,16 +4,49 @@ import android.app.ProgressDialog; @@ -4,16 +4,49 @@ import android.app.ProgressDialog;
4 import android.content.Context; 4 import android.content.Context;
5 import android.content.Intent; 5 import android.content.Intent;
6 import android.databinding.DataBindingUtil; 6 import android.databinding.DataBindingUtil;
  7 +import android.databinding.Observable;
7 import android.os.Bundle; 8 import android.os.Bundle;
8 import android.os.CountDownTimer; 9 import android.os.CountDownTimer;
9 import android.support.annotation.NonNull; 10 import android.support.annotation.NonNull;
  11 +import android.text.TextUtils;
  12 +import android.view.View;
  13 +import android.widget.Button;
  14 +import android.widget.EditText;
  15 +import android.widget.ImageButton;
10 16
11 import com.cnlive.goldenline.R; 17 import com.cnlive.goldenline.R;
  18 +import com.cnlive.goldenline.api.UserAPI;
  19 +import com.cnlive.goldenline.application.GoldenLineApplication;
12 import com.cnlive.goldenline.databinding.ActivityRegisterBinding; 20 import com.cnlive.goldenline.databinding.ActivityRegisterBinding;
  21 +import com.cnlive.goldenline.model.User;
  22 +import com.cnlive.goldenline.model.mine.SyncUserRequestBean;
13 import com.cnlive.goldenline.ui.base.BaseActivity; 23 import com.cnlive.goldenline.ui.base.BaseActivity;
  24 +import com.cnlive.goldenline.ui.base.GoldenlineCall;
  25 +import com.cnlive.goldenline.util.ChannelUtil;
  26 +import com.cnlive.goldenline.util.RestAdapterUtils;
  27 +import com.cnlive.goldenline.util.SPUtils;
  28 +import com.cnlive.goldenline.util.ShareSdkUtil;
  29 +import com.cnlive.goldenline.util.SystemTools;
  30 +import com.cnlive.goldenline.util.ToastUtil;
14 import com.cnlive.goldenline.util.UserService; 31 import com.cnlive.goldenline.util.UserService;
15 import com.cnlive.goldenline.viewmodel.LoginViewModel; 32 import com.cnlive.goldenline.viewmodel.LoginViewModel;
  33 +import com.cnlive.libs.user.IUserService;
  34 +import com.cnlive.libs.user.UserUtil;
16 import com.cnlive.libs.user.model.DataEntity; 35 import com.cnlive.libs.user.model.DataEntity;
  36 +import com.cnlive.libs.user.model.UserData;
  37 +
  38 +import java.util.HashMap;
  39 +import java.util.Locale;
  40 +
  41 +import butterknife.BindView;
  42 +import cn.sharesdk.framework.Platform;
  43 +import cn.sharesdk.framework.PlatformActionListener;
  44 +import cn.sharesdk.sina.weibo.SinaWeibo;
  45 +import cn.sharesdk.tencent.qq.QQ;
  46 +import cn.sharesdk.wechat.friends.Wechat;
  47 +import retrofit.Callback;
  48 +import retrofit.RetrofitError;
  49 +import retrofit.client.Response;
17 50
18 /** 51 /**
19 * Description: 登录页面 52 * Description: 登录页面
@@ -24,12 +57,28 @@ public class RegisterActivity extends BaseActivity { @@ -24,12 +57,28 @@ public class RegisterActivity extends BaseActivity {
24 57
25 58
26 private LoginViewModel loginViewModel; 59 private LoginViewModel loginViewModel;
  60 + ActivityRegisterBinding activityRegisterBinding;
27 61
28 public static void start(@NonNull Context context) { 62 public static void start(@NonNull Context context) {
29 Intent starter = new Intent(context, RegisterActivity.class); 63 Intent starter = new Intent(context, RegisterActivity.class);
30 context.startActivity(starter); 64 context.startActivity(starter);
31 } 65 }
32 - 66 + @BindView(R.id.imabutton_colse)
  67 + protected ImageButton imabutton_colse;
  68 + @BindView(R.id.imabutton_wx)
  69 + protected ImageButton imabutton_wx;
  70 + @BindView(R.id.imabutton_wb)
  71 + protected ImageButton imabutton_wb;
  72 + @BindView(R.id.imabutton_qq)
  73 + protected ImageButton imabutton_qq;
  74 + @BindView(R.id.button_sendcode)
  75 + protected Button button_sendcode;
  76 + @BindView(R.id.button_login)
  77 + protected Button button_login;
  78 + @BindView(R.id.et_phone)
  79 + protected EditText et_phone;
  80 + @BindView(R.id.et_code)
  81 + protected EditText et_code;
33 /** 82 /**
34 * 当前时间 83 * 当前时间
35 */ 84 */
@@ -51,13 +100,50 @@ public class RegisterActivity extends BaseActivity { @@ -51,13 +100,50 @@ public class RegisterActivity extends BaseActivity {
51 @Override 100 @Override
52 protected void onCreate(Bundle savedInstanceState) { 101 protected void onCreate(Bundle savedInstanceState) {
53 super.onCreate(savedInstanceState); 102 super.onCreate(savedInstanceState);
54 - ActivityRegisterBinding activityRegisterBinding= DataBindingUtil.setContentView(this,R.layout.activity_register);  
55 - loginViewModel=new LoginViewModel(activityRegisterBinding,RegisterActivity.this); 103 + setContentView(R.layout.activity_register);
  104 + activityRegisterBinding = DataBindingUtil.setContentView(this, R.layout.activity_register);
  105 + loginViewModel = new LoginViewModel(activityRegisterBinding, RegisterActivity.this);
56 activityRegisterBinding.setLoginViewModel(loginViewModel); 106 activityRegisterBinding.setLoginViewModel(loginViewModel);
57 -// setContentView(R.layout.activity_register);  
58 -// mUserService = new UserService(this); 107 + //判断是否是电话号码
  108 + loginViewModel.isPhone.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
  109 + @Override
  110 + public void onPropertyChanged(Observable observable, int i) {
  111 + if (loginViewModel.isPhone.get()) {
  112 + activityRegisterBinding.buttonSendcode.setBackgroundResource(R.mipmap.verificationcode_canuse);
  113 + activityRegisterBinding.buttonSendcode.setTextColor(GoldenLineApplication.getInstance().getResources().getColor(R.color.color_ff6633));
  114 + activityRegisterBinding.buttonSendcode.setEnabled(true);
  115 + } else {
  116 + activityRegisterBinding.buttonSendcode.setBackgroundResource(R.mipmap.verificationcode_nouse);
  117 + activityRegisterBinding.buttonSendcode.setTextColor(GoldenLineApplication.getInstance().getResources().getColor(R.color.color_959595));
  118 + activityRegisterBinding.buttonSendcode.setEnabled(false);
  119 + }
  120 + }
  121 + });
  122 + loginViewModel.isCodeRight.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
  123 + @Override
  124 + public void onPropertyChanged(Observable observable, int i) {
  125 + if ((loginViewModel.isCodeRight.get())) {
  126 + activityRegisterBinding.buttonLogin.setBackgroundResource(R.drawable.login_canuse);
  127 + activityRegisterBinding.buttonLogin.setEnabled(true);
  128 + } else {
  129 + activityRegisterBinding.buttonLogin.setBackgroundResource(R.drawable.login_nouse);
  130 + activityRegisterBinding.buttonLogin.setEnabled(false);
  131 + }
  132 + }
  133 + });
59 134
60 -// initData(); 135 + mUserService = new UserService(this);
  136 +
  137 + initData();
  138 + }
  139 +
  140 + private void initData() {
  141 + imabutton_colse.setOnClickListener(this);
  142 + imabutton_wx.setOnClickListener(this);
  143 + imabutton_wb.setOnClickListener(this);
  144 + imabutton_qq.setOnClickListener(this);
  145 + button_sendcode.setOnClickListener(this);
  146 + button_login.setOnClickListener(this);
61 } 147 }
62 148
63 @Override 149 @Override
@@ -65,17 +151,249 @@ public class RegisterActivity extends BaseActivity { @@ -65,17 +151,249 @@ public class RegisterActivity extends BaseActivity {
65 super.onResume(); 151 super.onResume();
66 } 152 }
67 153
  154 + @Override
  155 + public void onClick(View v) {
  156 + super.onClick(v);
  157 + switch (v.getId()) {
  158 + case R.id.imabutton_colse://关闭
  159 + this.finish();
  160 + break;
  161 + case R.id.imabutton_wx://微信登录
  162 + getOtherInfo("1", Wechat.NAME);
  163 + showLogin();
  164 + break;
  165 + case R.id.imabutton_wb://微博登录
  166 + getOtherInfo("2", SinaWeibo.NAME);
  167 + showLogin();
  168 + break;
  169 + case R.id.imabutton_qq://qq登录
  170 + getOtherInfo("3", QQ.NAME);
  171 + showLogin();
  172 + break;
  173 + case R.id.button_sendcode://发送验证码
  174 + UserUtil.sendMessage(IUserService.QUICK_LOGIN, et_phone.getText().toString(), new MobileCall());
  175 + break;
  176 + case R.id.button_login://登录
  177 + showLogin();
  178 + UserUtil.quickLogin(String.valueOf(et_phone.getText()), String.valueOf(et_code.getText()), ChannelUtil.getChannelFromApk(this), userDataCall);
  179 + break;
  180 +
  181 + default:
  182 + break;
  183 + }
  184 + }
  185 + /**
  186 + * 显示等待框
  187 + */
  188 + private void showLogin() {
  189 + progressDialog = ProgressDialog.show(this, "登录中...", "请稍候...", true, false);
  190 + progressDialog.setCancelable(true);// 设置是否可以通过点击Back键取消
  191 + progressDialog.setCanceledOnTouchOutside(false);// 设置在点击Dialog外是否取消Dialog进度条
  192 + }
  193 +
  194 + /**
  195 + * 发送验证码sdk
  196 + */
  197 + class MobileCall extends GoldenlineCall {
  198 + @Override
  199 + protected void dowork(int what, String extra, Object obj) {
  200 + switch (what) {
  201 + case IUserService.SUCCESS:
  202 + ToastUtil.showToast("验证码已发送");
  203 + startTimer();
  204 + break;
  205 + default:
  206 + ToastUtil.showToast("验证码发送失败");
  207 + updateSendButtonText(true);
  208 + break;
  209 + }
  210 +
  211 + }
  212 +
  213 + /**
  214 + * 开始计数器
  215 + */
  216 + private void startTimer() {
  217 + countDownTimer = new CountDownTimer(COUNTDOWN_TIME * 1000, 990) {
  218 + @Override
  219 + public void onTick(long leftTimeInMilliseconds) {
  220 + long seconds = leftTimeInMilliseconds / 1000;
  221 + count = (int) (seconds % 60);
  222 + updateSendButtonText(false);
  223 + }
  224 +
  225 + @Override
  226 + public void onFinish() {
  227 + updateSendButtonText(true);
  228 + }
  229 +
  230 + };
  231 + countDownTimer.start();
  232 + }
  233 +
  234 + /**
  235 + * 更新按钮的状态
  236 + *
  237 + * @param showNormal
  238 + */
  239 + private void updateSendButtonText(boolean showNormal) {
  240 + if (showNormal) {
  241 + button_sendcode.setText(getResources().getString(R.string.logoin_getcode));
  242 + button_sendcode.setBackgroundResource(R.mipmap.verificationcode_canuse);
  243 + button_sendcode.setTextColor(getResources().getColor(R.color.color_ff6633));
  244 + button_sendcode.setEnabled(true);
  245 + } else {
  246 + String s = String.format(Locale.CHINESE, getString(R.string.format_verify_countdown), count);
  247 + button_sendcode.setText(s);
  248 + button_sendcode.setBackgroundResource(R.mipmap.verificationcode_nouse);
  249 + button_sendcode.setTextColor(getResources().getColor(R.color.color_959595));
  250 + button_sendcode.setEnabled(false);
  251 + }
  252 + }
  253 + }
  254 +
  255 + /**
  256 + * 登陆完成后调用此方法同步用户其他信息
  257 + */
  258 + public void doNetWork(final DataEntity data) {
  259 + final UserAPI userApi = RestAdapterUtils.getRestAPI(UserAPI.class);
  260 + SyncUserRequestBean request = new SyncUserRequestBean(this);
  261 + request.setEmail(data.getEmail());
  262 + request.setExtInfo(data.getExtInfo());
  263 + request.setFaceUrl(data.getFaceUrl());
  264 + request.setGender(data.getGender().equals("m") ? 0 : (data.getGender().equals("f") ? 1 : 2));
  265 + request.sethUid(data.gethUid());
  266 + request.setLocation(data.getLocation());
  267 + request.setMobile(data.getMobile());
  268 + request.setNickName(data.getNickName());
  269 + request.setUid(data.getUid());
  270 + userApi.syncUserById(request, new Callback<User>() {
  271 + @Override
  272 + public void success(User user, Response response) {
  273 + progressDialog.dismiss();
  274 + if (null != user && user.getErrorCode().equals("0")) {
  275 + mUserService.setUserInfo(user, "");
  276 + SPUtils.put(RegisterActivity.this, "isSubscribeSuccess", true);
  277 + //登录成功关闭页面
  278 + finish();
  279 + }else{
  280 + ToastUtil.showToast(getString(R.string.login_error));
  281 + }
  282 + }
  283 +
  284 + @Override
  285 + public void failure(RetrofitError error) {
  286 + ToastUtil.showToast(getString(R.string.login_error));
  287 + progressDialog.dismiss();
  288 + }
  289 + });
  290 + }
  291 +
  292 + public void getOtherInfo(final String tag, String s) {
  293 + ShareSdkUtil.loginThirdPlatform(RegisterActivity.this, s, new PlatformActionListener() {
  294 + @Override
  295 + public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {//授权成功
68 296
  297 + progressDialog.dismiss();
69 298
  299 + if (null != hashMap && hashMap.size() > 0) {
  300 + if ("1" == tag) {
  301 + //微信登录
  302 + String uid = (String) hashMap.get("unionid");
  303 + String nick = platform.getDb().getUserName();
  304 + String location = (String) hashMap.get("city");
  305 + String avatar = (String) hashMap.get("headimgurl");
  306 + //为了红包提现,把uid传为openid
  307 + String openid = (String) hashMap.get("openid");
  308 + String userSex = "n";
  309 + int sex = (int) hashMap.get("sex");
  310 + if (sex == 1) {
  311 + userSex = "m";
  312 + } else if (sex == 2) {
  313 + userSex = "f";
  314 + }
  315 + UserUtil.thirdPartyLogin(3, uid, nick, userSex, location, avatar,
  316 + ChannelUtil.getChannelFromApk(RegisterActivity.this), userDataCall);
  317 + }else if ("2" == tag) {
  318 + //微博登录
  319 + String uid = platform.getDb().getUserId();
  320 + String nick = (String) hashMap.get("name");
  321 + String location = (String) hashMap.get("location");
  322 + String userSex = (String) hashMap.get("gender");
  323 + String avatar = (String) hashMap.get("profile_image_url");
  324 + UserUtil.thirdPartyLogin(1, uid, nick, userSex, location, avatar,
  325 + ChannelUtil.getChannelFromApk(RegisterActivity.this), userDataCall);
  326 + } else if("3" == tag){
  327 + //QQ登录
  328 + String uid = platform.getDb().getUserId();
  329 + String nick = (String) hashMap.get("nickname");
  330 + String location = (String) hashMap.get("city");
  331 + String avatar = hashMap.get("figureurl_qq_2").toString();
  332 + String userSex = "n";
  333 + String sex = (String) hashMap.get("gender");
  334 + if (sex.equals("男")) {
  335 + userSex = "m";
  336 + } else if (sex.equals("女")) {
  337 + userSex = "f";
  338 + }
  339 + UserUtil.thirdPartyLogin(2, uid, nick, userSex, location, avatar,
  340 + ChannelUtil.getChannelFromApk(RegisterActivity.this), userDataCall);
  341 + }
  342 + }
  343 + }
70 344
  345 + @Override
  346 + public void onError(Platform platform, int i, Throwable throwable) {//授权失败
  347 + progressDialog.dismiss();
  348 + }
71 349
  350 + @Override
  351 + public void onCancel(Platform platform, int i) {//取消
  352 + SystemTools.show_msg(getBaseContext(), "已取消");
  353 + progressDialog.dismiss();
  354 + }
  355 + });
  356 + }
  357 +
  358 + private GoldenlineCall userDataCall = new GoldenlineCall() {
  359 + @Override
  360 + protected void dowork(int what, String extra, Object obj) {
  361 + UserData userData = (UserData) obj;
  362 + DataEntity data = userData.getData();
  363 + GoldenLineApplication.mEdit.clear();
  364 + GoldenLineApplication.mEdit.putBoolean("isQuckLogin", true);
  365 + GoldenLineApplication.mEdit.putString("uid", data.getUid());
  366 + GoldenLineApplication.mEdit.putString("hUid", data.gethUid());
  367 + GoldenLineApplication.mEdit.apply();
  368 + if (null != data) {
  369 + //手机号为空必须要进行绑定,这是正在上演的逻辑
  370 + if(TextUtils.isEmpty(data.getMobile())){
  371 + Intent starter = new Intent(RegisterActivity.this, UpdatePhoneActivity.class);
  372 + starter.putExtra("title","绑定手机号");
  373 + starter.putExtra("uid",data.getUid());
  374 + starter.putExtra("data",data);
  375 + startActivityForResult(starter,101);
  376 + }else{
  377 + doNetWork(data);
  378 + }
  379 + }
  380 + }
  381 +
  382 + @Override
  383 + public void onState(int what, String extra, Object obj) {
  384 + super.onState(what, extra, obj);
  385 + if (what != IUserService.SUCCESS) {
  386 + progressDialog.dismiss();
  387 + }
  388 + }
  389 + };
72 @Override 390 @Override
73 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 391 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
74 super.onActivityResult(requestCode, resultCode, data); 392 super.onActivityResult(requestCode, resultCode, data);
75 - if(resultCode == RESULT_OK){ 393 + if (resultCode == RESULT_OK) {
76 DataEntity dataEntity = (DataEntity) (data.getSerializableExtra("data")); 394 DataEntity dataEntity = (DataEntity) (data.getSerializableExtra("data"));
77 395
78 - loginViewModel. doNetWork(dataEntity); 396 + doNetWork(dataEntity);
79 } 397 }
80 } 398 }
81 } 399 }
app/src/main/java/com/cnlive/goldenline/ui/base/DBBaseFragment.java 0 → 100644
  1 +package com.cnlive.goldenline.ui.base;
  2 +
  3 +import android.databinding.DataBindingUtil;
  4 +import android.databinding.ViewDataBinding;
  5 +import android.graphics.drawable.AnimationDrawable;
  6 +import android.os.Bundle;
  7 +import android.support.annotation.Nullable;
  8 +import android.support.v4.app.Fragment;
  9 +import android.view.LayoutInflater;
  10 +import android.view.View;
  11 +import android.view.ViewGroup;
  12 +import android.widget.ImageView;
  13 +import android.widget.LinearLayout;
  14 +import android.widget.RelativeLayout;
  15 +
  16 +import com.cnlive.goldenline.R;
  17 +
  18 +
  19 +/**
  20 + * Created by ZJL on 2017/5/14.
  21 + */
  22 +public abstract class DBBaseFragment<SV extends ViewDataBinding> extends Fragment {
  23 +
  24 + // 布局view
  25 + protected SV bindingView;
  26 + // fragment是否显示了
  27 + protected boolean mIsVisible = false;
  28 + // 加载中
  29 + private LinearLayout mLlProgressBar;
  30 + // 加载失败
  31 + private LinearLayout mRefresh;
  32 + // 内容布局
  33 + protected RelativeLayout mContainer;
  34 + // 动画
  35 + private AnimationDrawable mAnimationDrawable;
  36 +
  37 + @Nullable
  38 + @Override
  39 + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  40 + View ll = inflater.inflate(R.layout.fragment_base, null);
  41 + bindingView = DataBindingUtil.inflate(getActivity().getLayoutInflater(), setContent(), null, false);
  42 + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
  43 + bindingView.getRoot().setLayoutParams(params);
  44 + mContainer = (RelativeLayout) ll.findViewById(R.id.container);
  45 + mContainer.addView(bindingView.getRoot());
  46 + return ll;
  47 + }
  48 +
  49 + /**
  50 + * 在这里实现Fragment数据的缓加载.
  51 + */
  52 + @Override
  53 + public void setUserVisibleHint(boolean isVisibleToUser) {
  54 + super.setUserVisibleHint(isVisibleToUser);
  55 + if (getUserVisibleHint()) {
  56 + mIsVisible = true;
  57 + onVisible();
  58 + } else {
  59 + mIsVisible = false;
  60 + onInvisible();
  61 + }
  62 + }
  63 +
  64 + protected void onInvisible() {
  65 + }
  66 +
  67 + /**
  68 + * 显示时加载数据,需要这样的使用
  69 + * 注意声明 isPrepared,先初始化
  70 + * 生命周期会先执行 setUserVisibleHint 再执行onActivityCreated
  71 + * 在 onActivityCreated 之后第一次显示加载数据,只加载一次
  72 + */
  73 + protected void loadData() {
  74 + }
  75 +
  76 + protected void onVisible() {
  77 + loadData();
  78 + }
  79 +
  80 + @Override
  81 + public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  82 + super.onActivityCreated(savedInstanceState);
  83 + mLlProgressBar = getView(R.id.ll_progress_bar);
  84 + ImageView img = getView(R.id.img_progress);
  85 +
  86 + // 加载动画
  87 + mAnimationDrawable = (AnimationDrawable) img.getDrawable();
  88 + // 默认进入页面就开启动画
  89 + if (!mAnimationDrawable.isRunning()) {
  90 + mAnimationDrawable.start();
  91 + }
  92 + mRefresh = getView(R.id.ll_error_refresh);
  93 + // 点击加载失败布局
  94 + mRefresh.setOnClickListener(new View.OnClickListener() {
  95 + @Override
  96 + public void onClick(View view) {
  97 + showLoading();
  98 + onRefresh();
  99 + }
  100 + });
  101 + bindingView.getRoot().setVisibility(View.GONE);
  102 +
  103 + }
  104 +
  105 + protected <T extends View> T getView(int id) {
  106 + return (T) getView().findViewById(id);
  107 + }
  108 +
  109 + /**
  110 + * 布局
  111 + */
  112 + public abstract int setContent();
  113 +
  114 + /**
  115 + * 加载失败后点击后的操作
  116 + */
  117 + protected void onRefresh() {
  118 +
  119 + }
  120 +
  121 + /**
  122 + * 显示加载中状态
  123 + */
  124 + protected void showLoading() {
  125 + if (mLlProgressBar.getVisibility() != View.VISIBLE) {
  126 + mLlProgressBar.setVisibility(View.VISIBLE);
  127 + }
  128 + // 开始动画
  129 + if (!mAnimationDrawable.isRunning()) {
  130 + mAnimationDrawable.start();
  131 + }
  132 + if (bindingView.getRoot().getVisibility() != View.GONE) {
  133 + bindingView.getRoot().setVisibility(View.GONE);
  134 + }
  135 + if (mRefresh.getVisibility() != View.GONE) {
  136 + mRefresh.setVisibility(View.GONE);
  137 + }
  138 + }
  139 +
  140 + /**
  141 + * 加载完成的状态
  142 + */
  143 + protected void showContentView() {
  144 + if (mLlProgressBar.getVisibility() != View.GONE) {
  145 + mLlProgressBar.setVisibility(View.GONE);
  146 + }
  147 + // 停止动画
  148 + if (mAnimationDrawable.isRunning()) {
  149 + mAnimationDrawable.stop();
  150 + }
  151 + if (mRefresh.getVisibility() != View.GONE) {
  152 + mRefresh.setVisibility(View.GONE);
  153 + }
  154 + if (bindingView.getRoot().getVisibility() != View.VISIBLE) {
  155 + bindingView.getRoot().setVisibility(View.VISIBLE);
  156 + }
  157 + }
  158 +
  159 + /**
  160 + * 加载失败点击重新加载的状态
  161 + */
  162 + protected void showError() {
  163 + if (mLlProgressBar.getVisibility() != View.GONE) {
  164 + mLlProgressBar.setVisibility(View.GONE);
  165 + }
  166 + // 停止动画
  167 + if (mAnimationDrawable.isRunning()) {
  168 + mAnimationDrawable.stop();
  169 + }
  170 + if (mRefresh.getVisibility() != View.VISIBLE) {
  171 + mRefresh.setVisibility(View.VISIBLE);
  172 + }
  173 + if (bindingView.getRoot().getVisibility() != View.GONE) {
  174 + bindingView.getRoot().setVisibility(View.GONE);
  175 + }
  176 + }
  177 +
  178 + @Override
  179 + public void onDestroy() {
  180 + super.onDestroy();
  181 + }
  182 +
  183 + public void removeSubscription() {
  184 + }
  185 +}
app/src/main/java/com/cnlive/goldenline/ui/fragment/MainFragment.java 0 → 100644
  1 +package com.cnlive.goldenline.ui.fragment;
  2 +
  3 +import android.os.Bundle;
  4 +import android.support.annotation.Nullable;
  5 +import android.util.SparseArray;
  6 +import android.view.View;
  7 +import android.widget.RelativeLayout;
  8 +
  9 +import com.cnlive.goldenline.R;
  10 +import com.cnlive.goldenline.api.CmsAPI;
  11 +import com.cnlive.goldenline.databinding.FragmentMainBinding;
  12 +import com.cnlive.goldenline.model.Tabbean;
  13 +import com.cnlive.goldenline.ui.activity.CheckDayActivity;
  14 +import com.cnlive.goldenline.ui.activity.SearchResultActivity;
  15 +import com.cnlive.goldenline.ui.adapter.ViewType;
  16 +import com.cnlive.goldenline.ui.base.DBBaseFragment;
  17 +import com.cnlive.goldenline.ui.model.RecyclerViewNormalBean;
  18 +import com.cnlive.goldenline.util.RestAdapterUtils;
  19 +import com.cnlive.goldenline.util.StringUtils;
  20 +import com.cnlive.goldenline.util.TimeUtil;
  21 +import com.cnlive.goldenline.util.UserService;
  22 +
  23 +/**
  24 + * Created by ZJL on 2017/5/14.
  25 + */
  26 +
  27 +public class MainFragment extends DBBaseFragment<FragmentMainBinding> implements View.OnClickListener{
  28 + private UserService mUserService;
  29 + private CmsAPI api;
  30 + private SparseArray<RecyclerViewNormalBean> dataArray = new SparseArray<>();
  31 + @Override
  32 + public int setContent() {
  33 + return R.layout.fragment_main;
  34 + }
  35 +
  36 + @Override
  37 + public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  38 + super.onActivityCreated(savedInstanceState);
  39 + mUserService = new UserService(getContext());
  40 + bindingView.frHomeImgCalendar.setOnClickListener(this);
  41 + bindingView.frHomeImgCalendarScroll.setOnClickListener(this);
  42 + bindingView.frHomeImgSearch.setOnClickListener(this);
  43 + bindingView.frHomeEtSearch.setOnClickListener(this);
  44 + bindingView.frHomeEtSearch.setHint(StringUtils.fromatETHint("搜索您喜欢的内容", 11));
  45 + api = RestAdapterUtils.getRestAPI(CmsAPI.class);
  46 + int currentDay = TimeUtil.getInstance().getCurrentDay();
  47 + bindingView.frHomeTvCalendar.setText(String.valueOf(currentDay));
  48 + bindingView.frHomeTvCalendarScroll.setText(String.valueOf(currentDay));
  49 + generateVideoType();
  50 +// initRecyclerView();
  51 +// initData2AdapterData();
  52 + bindingView.frHomeImgCalendar.setOnClickListener(this);
  53 + bindingView.frHomeImgCalendarScroll.setOnClickListener(this);
  54 + }
  55 +
  56 + @Override
  57 + public void onClick(View view) {
  58 + switch (view.getId()) {
  59 + case R.id.fr_home_img_calendar:
  60 + case R.id.fr_home_img_calendar_scroll:
  61 + CheckDayActivity.start(getActivity());
  62 + break;
  63 + case R.id.fr_home_img_search:
  64 + case R.id.fr_home_et_search:
  65 + SearchResultActivity.start(getActivity());
  66 + break;
  67 + }
  68 + }
  69 +
  70 + public class ClickPresenter {
  71 + public void onAddClick(View v) {
  72 + }
  73 + }
  74 +
  75 + private void generateVideoType() {
  76 + Tabbean tabbean = new Tabbean();
  77 + tabbean.setTabImgRes(R.drawable.click_refresh);
  78 + RecyclerViewNormalBean normalBean = new RecyclerViewNormalBean();
  79 + normalBean.setT(tabbean);
  80 + normalBean.setDataType(ViewType.TYPE_DEFAULT_BANNER);
  81 + dataArray.put(0, normalBean);
  82 +
  83 + Tabbean tab = new Tabbean();
  84 + tab.setTabName("舞台剧");
  85 + tab.setTabImgRes(R.mipmap.wutaiju);
  86 + tab.setTabSort(1);
  87 + RecyclerViewNormalBean data = new RecyclerViewNormalBean();
  88 + data.setT(tab);
  89 + data.setDataType(ViewType.TYPE_VIDEOTYPE);
  90 + dataArray.put(1, data);
  91 +
  92 + Tabbean tab1 = new Tabbean();
  93 + tab1.setTabName("演唱会");
  94 + tab1.setTabImgRes(R.mipmap.yanchanghui);
  95 + tab1.setTabSort(2);
  96 + RecyclerViewNormalBean data1 = new RecyclerViewNormalBean();
  97 + data1.setT(tab1);
  98 + data1.setDataType(ViewType.TYPE_VIDEOTYPE);
  99 + dataArray.put(2, data1);
  100 +
  101 + Tabbean tab2 = new Tabbean();
  102 + tab2.setTabName("相声");
  103 + tab2.setTabImgRes(R.mipmap.xiangsheng);
  104 + tab2.setTabSort(3);
  105 + RecyclerViewNormalBean data2 = new RecyclerViewNormalBean();
  106 + data2.setT(tab2);
  107 + data2.setDataType(ViewType.TYPE_VIDEOTYPE);
  108 + dataArray.put(3, data2);
  109 +
  110 + Tabbean tab3 = new Tabbean();
  111 + tab3.setTabName("儿童剧");
  112 + tab3.setTabSort(4);
  113 + tab3.setTabImgRes(R.mipmap.ertongju);
  114 + RecyclerViewNormalBean data3 = new RecyclerViewNormalBean();
  115 + data3.setT(tab3);
  116 + data3.setDataType(ViewType.TYPE_VIDEOTYPE);
  117 + dataArray.put(4, data3);
  118 +
  119 + Tabbean tab4 = new Tabbean();
  120 + tab4.setTabName("更多");
  121 + tab4.setTabSort(5);
  122 + tab4.setTabImgRes(R.mipmap.gengduo);
  123 + RecyclerViewNormalBean data4 = new RecyclerViewNormalBean();
  124 + data4.setT(tab4);
  125 + data4.setDataType(ViewType.TYPE_VIDEOTYPE);
  126 + dataArray.put(5, data4);
  127 + }
  128 +}
app/src/main/java/com/cnlive/goldenline/viewmodel/LoginViewModel.java
1 package com.cnlive.goldenline.viewmodel; 1 package com.cnlive.goldenline.viewmodel;
2 2
3 import android.app.Activity; 3 import android.app.Activity;
4 -import android.app.ProgressDialog;  
5 import android.content.Context; 4 import android.content.Context;
6 -import android.content.Intent;  
7 import android.databinding.BaseObservable; 5 import android.databinding.BaseObservable;
8 -import android.os.CountDownTimer; 6 +import android.databinding.ObservableBoolean;
9 import android.text.Editable; 7 import android.text.Editable;
10 -import android.text.TextUtils;  
11 import android.util.Log; 8 import android.util.Log;
12 import android.view.View; 9 import android.view.View;
13 10
14 -import com.cnlive.goldenline.R;  
15 -import com.cnlive.goldenline.api.UserAPI;  
16 -import com.cnlive.goldenline.application.GoldenLineApplication;  
17 import com.cnlive.goldenline.databinding.ActivityRegisterBinding; 11 import com.cnlive.goldenline.databinding.ActivityRegisterBinding;
18 -import com.cnlive.goldenline.model.User;  
19 -import com.cnlive.goldenline.model.mine.SyncUserRequestBean;  
20 -import com.cnlive.goldenline.ui.activity.UpdatePhoneActivity;  
21 -import com.cnlive.goldenline.ui.base.GoldenlineCall;  
22 -import com.cnlive.goldenline.util.ChannelUtil;  
23 -import com.cnlive.goldenline.util.RestAdapterUtils;  
24 -import com.cnlive.goldenline.util.SPUtils;  
25 -import com.cnlive.goldenline.util.ShareSdkUtil;  
26 import com.cnlive.goldenline.util.StringUtils; 12 import com.cnlive.goldenline.util.StringUtils;
27 -import com.cnlive.goldenline.util.SystemTools;  
28 -import com.cnlive.goldenline.util.ToastUtil;  
29 -import com.cnlive.goldenline.util.UserService;  
30 -import com.cnlive.libs.user.IUserService;  
31 -import com.cnlive.libs.user.UserUtil;  
32 -import com.cnlive.libs.user.model.DataEntity;  
33 -import com.cnlive.libs.user.model.UserData;  
34 -  
35 -import java.util.HashMap;  
36 -import java.util.Locale;  
37 -  
38 -import cn.sharesdk.framework.Platform;  
39 -import cn.sharesdk.framework.PlatformActionListener;  
40 -import cn.sharesdk.sina.weibo.SinaWeibo;  
41 -import cn.sharesdk.tencent.qq.QQ;  
42 -import cn.sharesdk.wechat.friends.Wechat;  
43 -import retrofit.Callback;  
44 -import retrofit.RetrofitError;  
45 -import retrofit.client.Response;  
46 13
47 /** 14 /**
48 * Created by ZJL on 2017/5/10. 15 * Created by ZJL on 2017/5/10.
49 */ 16 */
50 17
51 public class LoginViewModel extends BaseObservable{ 18 public class LoginViewModel extends BaseObservable{
52 - /**  
53 - * 当前时间  
54 - */  
55 - private int count = COUNTDOWN_TIME;  
56 - /**  
57 - * 验证码计算时间  
58 - */  
59 - private final static int COUNTDOWN_TIME = 60;  
60 -  
61 - /**  
62 - * 倒数计数器  
63 - */  
64 - private CountDownTimer countDownTimer;  
65 -  
66 - private String mPhone;  
67 - private ActivityRegisterBinding activityRegisterBinding;  
68 - 19 + public final ObservableBoolean isPhone = new ObservableBoolean();
  20 + public final ObservableBoolean isCodeRight = new ObservableBoolean();
69 private String phone = ""; 21 private String phone = "";
70 - private ProgressDialog progressDialog;  
71 - private UserService mUserService;  
72 private Context context; 22 private Context context;
73 23
74 public LoginViewModel(ActivityRegisterBinding activityRegisterBinding, Context context){ 24 public LoginViewModel(ActivityRegisterBinding activityRegisterBinding, Context context){
75 - this.activityRegisterBinding=activityRegisterBinding;  
76 this.context=context; 25 this.context=context;
77 - mUserService = new UserService(context);  
78 - }  
79 - public String getMPhone() {  
80 - return mPhone;  
81 - }  
82 -  
83 - public void setMPhone(String mPhone) {  
84 - this.mPhone = mPhone;  
85 } 26 }
86 27
87 /** 28 /**
@@ -91,248 +32,23 @@ public class LoginViewModel extends BaseObservable{ @@ -91,248 +32,23 @@ public class LoginViewModel extends BaseObservable{
91 */ 32 */
92 public void formatCode(Editable code) { 33 public void formatCode(Editable code) {
93 if (phone.length() == 11 && StringUtils.checkPhoneNumber(phone.toString()) && code.length() == 6) { 34 if (phone.length() == 11 && StringUtils.checkPhoneNumber(phone.toString()) && code.length() == 6) {
94 - activityRegisterBinding.buttonLogin.setBackgroundResource(R.drawable.login_canuse);  
95 - activityRegisterBinding.buttonLogin.setEnabled(true); 35 + isCodeRight.set(true);
96 } else { 36 } else {
97 - activityRegisterBinding.buttonLogin.setBackgroundResource(R.drawable.login_nouse);  
98 - activityRegisterBinding.buttonLogin.setEnabled(false); 37 + isCodeRight.set(false);
99 } 38 }
100 } 39 }
101 public void phoneChanged(Editable phone) { 40 public void phoneChanged(Editable phone) {
102 Log.i("name","titleChanged"); 41 Log.i("name","titleChanged");
103 this.phone = phone.toString(); 42 this.phone = phone.toString();
104 if (phone.length() == 11 && StringUtils.checkPhoneNumber(phone.toString())) { 43 if (phone.length() == 11 && StringUtils.checkPhoneNumber(phone.toString())) {
105 - activityRegisterBinding.buttonSendcode.setBackgroundResource(R.mipmap.verificationcode_canuse);  
106 - activityRegisterBinding.buttonSendcode.setTextColor(GoldenLineApplication.getInstance().getResources().getColor(R.color.color_ff6633));  
107 - activityRegisterBinding.buttonSendcode.setEnabled(true); 44 + isPhone.set(true);
  45 +
108 } else { 46 } else {
109 - activityRegisterBinding.buttonSendcode.setBackgroundResource(R.mipmap.verificationcode_nouse);  
110 - activityRegisterBinding.buttonSendcode.setTextColor(GoldenLineApplication.getInstance().getResources().getColor(R.color.color_959595));  
111 - activityRegisterBinding.buttonSendcode.setEnabled(false);  
112 - }  
113 - }  
114 - public void sendSMS(View view){  
115 - UserUtil.sendMessage(IUserService.QUICK_LOGIN, activityRegisterBinding.etPhone.getText().toString(), new MobileCall()); 47 + isPhone.set(false);
116 48
117 - }  
118 - public void toLogin(View view){  
119 - showLogin();  
120 - UserUtil.quickLogin(String.valueOf(activityRegisterBinding.etPhone.getText()), String.valueOf(activityRegisterBinding.etCode.getText()), ChannelUtil.getChannelFromApk(context), userDataCall);  
121 - }  
122 - public void weixinLogin(View view){  
123 - getOtherInfo("1", Wechat.NAME);  
124 - showLogin();  
125 - }  
126 - public void weiboLogin(View view){  
127 - getOtherInfo("2", SinaWeibo.NAME);  
128 - showLogin();  
129 - }  
130 - public void qqLogin(View view){  
131 - getOtherInfo("3", QQ.NAME);  
132 - showLogin(); 49 + }
133 } 50 }
134 public void closeAct(View view){ 51 public void closeAct(View view){
135 ( (Activity)context).finish(); 52 ( (Activity)context).finish();
136 } 53 }
137 - /**  
138 - * 发送验证码sdk  
139 - */  
140 - class MobileCall extends GoldenlineCall {  
141 - @Override  
142 - protected void dowork(int what, String extra, Object obj) {  
143 - switch (what) {  
144 - case IUserService.SUCCESS:  
145 - ToastUtil.showToast("验证码已发送");  
146 - startTimer();  
147 - break;  
148 - default:  
149 - ToastUtil.showToast("验证码发送失败");  
150 - updateSendButtonText(true);  
151 - break;  
152 - }  
153 -  
154 - }  
155 -  
156 - /**  
157 - * 开始计数器  
158 - */  
159 - private void startTimer() {  
160 - countDownTimer = new CountDownTimer(COUNTDOWN_TIME * 1000, 990) {  
161 - @Override  
162 - public void onTick(long leftTimeInMilliseconds) {  
163 - long seconds = leftTimeInMilliseconds / 1000;  
164 - count = (int) (seconds % 60);  
165 - updateSendButtonText(false);  
166 - }  
167 -  
168 - @Override  
169 - public void onFinish() {  
170 - updateSendButtonText(true);  
171 - }  
172 -  
173 - };  
174 - countDownTimer.start();  
175 - }  
176 -  
177 - /**  
178 - * 更新按钮的状态  
179 - *  
180 - * @param showNormal  
181 - */  
182 - private void updateSendButtonText(boolean showNormal) {  
183 - if (showNormal) {  
184 - activityRegisterBinding.buttonSendcode.setText(GoldenLineApplication.getInstance().getResources().getString(R.string.logoin_getcode));  
185 - activityRegisterBinding.buttonSendcode.setBackgroundResource(R.mipmap.verificationcode_canuse);  
186 - activityRegisterBinding.buttonSendcode.setTextColor(GoldenLineApplication.getInstance().getResources().getColor(R.color.color_ff6633));  
187 - activityRegisterBinding.buttonSendcode.setEnabled(true);  
188 - } else {  
189 - String s = String.format(Locale.CHINESE, GoldenLineApplication.getInstance().getString(R.string.format_verify_countdown), count);  
190 - activityRegisterBinding.buttonSendcode.setText(s);  
191 - activityRegisterBinding.buttonSendcode.setBackgroundResource(R.mipmap.verificationcode_nouse);  
192 - activityRegisterBinding.buttonSendcode.setTextColor(GoldenLineApplication.getInstance().getResources().getColor(R.color.color_959595));  
193 - activityRegisterBinding.buttonSendcode.setEnabled(false);  
194 - }  
195 - }  
196 - }  
197 - /**  
198 - * 显示等待框  
199 - */  
200 - private void showLogin() {  
201 - progressDialog = ProgressDialog.show(context, "登录中...", "请稍候...", true, false);  
202 - progressDialog.setCancelable(true);// 设置是否可以通过点击Back键取消  
203 - progressDialog.setCanceledOnTouchOutside(false);// 设置在点击Dialog外是否取消Dialog进度条  
204 - }  
205 - private GoldenlineCall userDataCall = new GoldenlineCall() {  
206 - @Override  
207 - protected void dowork(int what, String extra, Object obj) {  
208 - UserData userData = (UserData) obj;  
209 - DataEntity data = userData.getData();  
210 - GoldenLineApplication.mEdit.clear();  
211 - GoldenLineApplication.mEdit.putBoolean("isQuckLogin", true);  
212 - GoldenLineApplication.mEdit.putString("uid", data.getUid());  
213 - GoldenLineApplication.mEdit.putString("hUid", data.gethUid());  
214 - GoldenLineApplication.mEdit.apply();  
215 - if (null != data) {  
216 - //手机号为空必须要进行绑定,这是正在上演的逻辑  
217 - if(TextUtils.isEmpty(data.getMobile())){  
218 - Intent starter = new Intent(context, UpdatePhoneActivity.class);  
219 - starter.putExtra("title","绑定手机号");  
220 - starter.putExtra("uid",data.getUid());  
221 - starter.putExtra("data",data);  
222 - ( (Activity)context).startActivityForResult(starter,101);  
223 - }else{  
224 - doNetWork(data);  
225 - }  
226 - }  
227 - }  
228 -  
229 - @Override  
230 - public void onState(int what, String extra, Object obj) {  
231 - super.onState(what, extra, obj);  
232 - if (what != IUserService.SUCCESS) {  
233 - progressDialog.dismiss();  
234 - }  
235 - }  
236 - };  
237 - /**  
238 - * 登陆完成后调用此方法同步用户其他信息  
239 - */  
240 - public void doNetWork(final DataEntity data) {  
241 - final UserAPI userApi = RestAdapterUtils.getRestAPI(UserAPI.class);  
242 - SyncUserRequestBean request = new SyncUserRequestBean(context);  
243 - request.setEmail(data.getEmail());  
244 - request.setExtInfo(data.getExtInfo());  
245 - request.setFaceUrl(data.getFaceUrl());  
246 - request.setGender(data.getGender().equals("m") ? 0 : (data.getGender().equals("f") ? 1 : 2));  
247 - request.sethUid(data.gethUid());  
248 - request.setLocation(data.getLocation());  
249 - request.setMobile(data.getMobile());  
250 - request.setNickName(data.getNickName());  
251 - request.setUid(data.getUid());  
252 - userApi.syncUserById(request, new Callback<User>() {  
253 - @Override  
254 - public void success(User user, Response response) {  
255 - progressDialog.dismiss();  
256 - if (null != user && user.getErrorCode().equals("0")) {  
257 - mUserService.setUserInfo(user, "");  
258 - SPUtils.put(context, "isSubscribeSuccess", true);  
259 - //登录成功关闭页面  
260 - ( (Activity)context).finish();  
261 - }else{  
262 - ToastUtil.showToast(GoldenLineApplication.getInstance().getString(R.string.login_error));  
263 - }  
264 - }  
265 -  
266 - @Override  
267 - public void failure(RetrofitError error) {  
268 - ToastUtil.showToast(GoldenLineApplication.getInstance().getString(R.string.login_error));  
269 - progressDialog.dismiss();  
270 - }  
271 - });  
272 - }  
273 - public void getOtherInfo(final String tag, String s) {  
274 - ShareSdkUtil.loginThirdPlatform(context, s, new PlatformActionListener() {  
275 - @Override  
276 - public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {//授权成功  
277 -  
278 - progressDialog.dismiss();  
279 -  
280 - if (null != hashMap && hashMap.size() > 0) {  
281 - if ("1" == tag) {  
282 - //微信登录  
283 - String uid = (String) hashMap.get("unionid");  
284 - String nick = platform.getDb().getUserName();  
285 - String location = (String) hashMap.get("city");  
286 - String avatar = (String) hashMap.get("headimgurl");  
287 - //为了红包提现,把uid传为openid  
288 - String openid = (String) hashMap.get("openid");  
289 - String userSex = "n";  
290 - int sex = (int) hashMap.get("sex");  
291 - if (sex == 1) {  
292 - userSex = "m";  
293 - } else if (sex == 2) {  
294 - userSex = "f";  
295 - }  
296 - UserUtil.thirdPartyLogin(3, uid, nick, userSex, location, avatar,  
297 - ChannelUtil.getChannelFromApk(context), userDataCall);  
298 - }else if ("2" == tag) {  
299 - //微博登录  
300 - String uid = platform.getDb().getUserId();  
301 - String nick = (String) hashMap.get("name");  
302 - String location = (String) hashMap.get("location");  
303 - String userSex = (String) hashMap.get("gender");  
304 - String avatar = (String) hashMap.get("profile_image_url");  
305 - UserUtil.thirdPartyLogin(1, uid, nick, userSex, location, avatar,  
306 - ChannelUtil.getChannelFromApk(context), userDataCall);  
307 - } else if("3" == tag){  
308 - //QQ登录  
309 - String uid = platform.getDb().getUserId();  
310 - String nick = (String) hashMap.get("nickname");  
311 - String location = (String) hashMap.get("city");  
312 - String avatar = hashMap.get("figureurl_qq_2").toString();  
313 - String userSex = "n";  
314 - String sex = (String) hashMap.get("gender");  
315 - if (sex.equals("男")) {  
316 - userSex = "m";  
317 - } else if (sex.equals("女")) {  
318 - userSex = "f";  
319 - }  
320 - UserUtil.thirdPartyLogin(2, uid, nick, userSex, location, avatar,  
321 - ChannelUtil.getChannelFromApk(context), userDataCall);  
322 - }  
323 - }  
324 - }  
325 -  
326 - @Override  
327 - public void onError(Platform platform, int i, Throwable throwable) {//授权失败  
328 - progressDialog.dismiss();  
329 - }  
330 -  
331 - @Override  
332 - public void onCancel(Platform platform, int i) {//取消  
333 - SystemTools.show_msg(GoldenLineApplication.getInstance().getBaseContext(), "已取消");  
334 - progressDialog.dismiss();  
335 - }  
336 - });  
337 - }  
338 } 54 }
app/src/main/java/com/cnlive/goldenline/viewmodel/MainFragmentModel.java 0 → 100644
  1 +package com.cnlive.goldenline.viewmodel;
  2 +
  3 +import android.content.Context;
  4 +import android.databinding.BaseObservable;
  5 +
  6 +import com.cnlive.goldenline.ui.fragment.MainFragment;
  7 +
  8 +/**
  9 + * Created by ZJL on 2017/5/15.
  10 + */
  11 +
  12 +public class MainFragmentModel extends BaseObservable {
  13 + private Context context;
  14 + public MainFragmentModel(Context context){
  15 + this.context=context;
  16 +
  17 + }
  18 +}
app/src/main/res/layout/activity_register.xml
@@ -62,7 +62,6 @@ @@ -62,7 +62,6 @@
62 android:textSize="14sp" /> 62 android:textSize="14sp" />
63 63
64 <Button 64 <Button
65 - android:onClick="@{loginViewModel::sendSMS}"  
66 android:id="@+id/button_sendcode" 65 android:id="@+id/button_sendcode"
67 android:layout_width="wrap_content" 66 android:layout_width="wrap_content"
68 android:layout_height="wrap_content" 67 android:layout_height="wrap_content"
@@ -120,7 +119,6 @@ @@ -120,7 +119,6 @@
120 </RelativeLayout> 119 </RelativeLayout>
121 120
122 <Button 121 <Button
123 - android:onClick="@{loginViewModel::toLogin}"  
124 android:id="@+id/button_login" 122 android:id="@+id/button_login"
125 android:layout_width="wrap_content" 123 android:layout_width="wrap_content"
126 android:layout_height="wrap_content" 124 android:layout_height="wrap_content"
@@ -164,7 +162,6 @@ @@ -164,7 +162,6 @@
164 android:layout_weight="1"> 162 android:layout_weight="1">
165 163
166 <ImageButton 164 <ImageButton
167 - android:onClick="@{loginViewModel::weixinLogin}"  
168 android:id="@+id/imabutton_wx" 165 android:id="@+id/imabutton_wx"
169 android:layout_width="wrap_content" 166 android:layout_width="wrap_content"
170 android:layout_height="wrap_content" 167 android:layout_height="wrap_content"
@@ -178,7 +175,6 @@ @@ -178,7 +175,6 @@
178 android:layout_weight="1"> 175 android:layout_weight="1">
179 176
180 <ImageButton 177 <ImageButton
181 - android:onClick="@{loginViewModel::weiboLogin}"  
182 android:id="@+id/imabutton_wb" 178 android:id="@+id/imabutton_wb"
183 android:layout_width="wrap_content" 179 android:layout_width="wrap_content"
184 android:layout_height="wrap_content" 180 android:layout_height="wrap_content"
@@ -187,7 +183,6 @@ @@ -187,7 +183,6 @@
187 </RelativeLayout> 183 </RelativeLayout>
188 184
189 <RelativeLayout 185 <RelativeLayout
190 - android:onClick="@{loginViewModel::qqLogin}"  
191 android:layout_width="wrap_content" 186 android:layout_width="wrap_content"
192 android:layout_height="wrap_content" 187 android:layout_height="wrap_content"
193 android:layout_weight="1"> 188 android:layout_weight="1">
app/src/main/res/layout/fragment_base.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<layout xmlns:android="http://schemas.android.com/apk/res/android">
  3 +
  4 + <LinearLayout
  5 + android:id="@+id/ll_root"
  6 + android:layout_width="match_parent"
  7 + android:layout_height="match_parent"
  8 + android:background="@color/gray_line_color"
  9 + android:orientation="vertical">
  10 +
  11 + <!--有可能直接显示(固定的布局,非必须,按需要添加)-->
  12 + <RelativeLayout
  13 + android:id="@+id/rl_content_part"
  14 + android:layout_width="match_parent"
  15 + android:layout_height="wrap_content" />
  16 +
  17 +
  18 + <RelativeLayout
  19 + android:id="@+id/container"
  20 + android:layout_width="match_parent"
  21 + android:layout_height="match_parent">
  22 +
  23 +
  24 + <!--加载失败-->
  25 + <LinearLayout
  26 + android:id="@+id/ll_error_refresh"
  27 + android:layout_width="match_parent"
  28 + android:layout_height="match_parent"
  29 + android:gravity="center"
  30 + android:orientation="vertical"
  31 + android:visibility="gone">
  32 +
  33 + <ImageView
  34 + android:id="@+id/img_err"
  35 + android:layout_width="wrap_content"
  36 + android:layout_height="wrap_content"
  37 + android:src="@mipmap/ic_launcher" />
  38 +
  39 + <TextView
  40 + android:layout_width="wrap_content"
  41 + android:layout_height="wrap_content"
  42 + android:layout_marginTop="15dp"
  43 + android:text="加载失败,点击重试"
  44 + android:textSize="15sp" />
  45 + </LinearLayout>
  46 +
  47 + <!--加载中..-->
  48 + <LinearLayout
  49 + android:id="@+id/ll_progress_bar"
  50 + android:layout_width="wrap_content"
  51 + android:layout_height="wrap_content"
  52 + android:layout_centerHorizontal="true"
  53 + android:layout_marginTop="80dp"
  54 + android:gravity="center_vertical">
  55 +
  56 + <ImageView
  57 + android:id="@+id/img_progress"
  58 + android:layout_width="wrap_content"
  59 + android:layout_height="wrap_content"
  60 + android:src="@mipmap/ic_launcher" />
  61 +
  62 + <TextView
  63 + android:layout_width="wrap_content"
  64 + android:layout_height="wrap_content"
  65 + android:layout_marginLeft="10dp"
  66 + android:text="努力加载中..."
  67 + android:textColor="@color/main_black"
  68 + android:textSize="14sp" />
  69 +
  70 + </LinearLayout>
  71 + </RelativeLayout>
  72 + </LinearLayout>
  73 +</layout>
0 \ No newline at end of file 74 \ No newline at end of file
app/src/main/res/layout/fragment_main.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<layout xmlns:android="http://schemas.android.com/apk/res/android">
  3 + <data>
  4 +
  5 + <variable
  6 + name="clickPresenter"
  7 + type="com.cnlive.goldenline.ui.fragment.MainFragment.ClickPresenter"/>
  8 + </data>
  9 +<RelativeLayout
  10 + xmlns:tools="http://schemas.android.com/tools"
  11 + android:layout_width="match_parent"
  12 + android:layout_height="match_parent"
  13 + android:background="@color/color_bg"
  14 + android:orientation="vertical">
  15 +
  16 + <include
  17 + layout="@layout/view_recyclerview"
  18 + android:layout_width="match_parent"
  19 + android:layout_height="wrap_content" />
  20 +
  21 + <LinearLayout
  22 + android:layout_width="match_parent"
  23 + android:layout_height="wrap_content"
  24 + android:orientation="vertical">
  25 +
  26 + <View
  27 + android:id="@+id/fake_status_bar"
  28 + android:layout_width="match_parent"
  29 + android:layout_height="5dp"
  30 + android:background="#28272d"
  31 + android:fitsSystemWindows="true"
  32 + android:visibility="invisible" />
  33 +
  34 + <!--搜索栏-->
  35 + <RelativeLayout
  36 + android:id="@+id/fr_home_layout_operation"
  37 + android:layout_width="match_parent"
  38 + android:layout_height="wrap_content"
  39 + android:background="#28272d"
  40 + android:paddingBottom="8dp"
  41 + android:paddingLeft="10dp"
  42 + android:paddingRight="19dp"
  43 + android:visibility="gone">
  44 +
  45 + <TextView
  46 + android:id="@+id/fr_home_et_search"
  47 + android:layout_width="297dp"
  48 + android:layout_height="27dp"
  49 + android:layout_alignParentLeft="true"
  50 + android:background="@drawable/home_search_edittet_bg"
  51 + android:drawableLeft="@mipmap/navigation_bar_search_icon"
  52 + android:drawablePadding="8dp"
  53 + android:text="搜索您喜欢的内容"
  54 + android:textColor="#999"
  55 + android:textColorHint="#999"
  56 + android:textSize="11sp" />
  57 +
  58 + <FrameLayout
  59 + android:layout_width="wrap_content"
  60 + android:layout_height="wrap_content"
  61 + android:layout_alignBottom="@id/fr_home_et_search"
  62 + android:layout_alignParentRight="true"
  63 + android:layout_alignTop="@id/fr_home_et_search">
  64 +
  65 + <ImageView
  66 + android:id="@+id/fr_home_img_calendar_scroll"
  67 + android:layout_width="32dp"
  68 + android:layout_height="32dp"
  69 + android:layout_gravity="center"
  70 + android:src="@mipmap/navigationbar_calender" />
  71 +
  72 + <TextView
  73 + android:id="@+id/fr_home_tv_calendar_scroll"
  74 + android:layout_width="wrap_content"
  75 + android:layout_height="wrap_content"
  76 + android:layout_gravity="center"
  77 + android:gravity="center_horizontal"
  78 + android:includeFontPadding="false"
  79 + android:paddingTop="3dp"
  80 + android:textColor="#fff"
  81 + android:textSize="9sp"
  82 + tools:text="12" />
  83 + </FrameLayout>
  84 + </RelativeLayout>
  85 +
  86 + <RelativeLayout
  87 + android:id="@+id/fr_home_layout_search"
  88 + android:layout_width="match_parent"
  89 + android:layout_height="wrap_content"
  90 + android:paddingBottom="8dp"
  91 + android:paddingLeft="10dp"
  92 + android:paddingRight="19dp">
  93 +
  94 + <FrameLayout
  95 + android:layout_width="wrap_content"
  96 + android:layout_height="wrap_content"
  97 + android:layout_alignParentRight="true">
  98 +
  99 + <ImageView
  100 + android:id="@+id/fr_home_img_calendar"
  101 + android:layout_width="wrap_content"
  102 + android:layout_height="27dp"
  103 + android:src="@mipmap/index_calendar_button" />
  104 +
  105 + <TextView
  106 + android:id="@+id/fr_home_tv_calendar"
  107 + android:layout_width="wrap_content"
  108 + android:layout_height="wrap_content"
  109 + android:layout_gravity="center"
  110 + android:gravity="center_horizontal"
  111 + android:includeFontPadding="false"
  112 + android:paddingTop="3dp"
  113 + android:textColor="#fff"
  114 + android:textSize="8sp"
  115 + tools:text="12" />
  116 + </FrameLayout>
  117 +
  118 + <ImageView
  119 + android:id="@+id/fr_home_img_search"
  120 + android:layout_width="wrap_content"
  121 + android:layout_height="27dp"
  122 + android:layout_alignParentLeft="true"
  123 + android:src="@mipmap/index_search_button" />
  124 + </RelativeLayout>
  125 + </LinearLayout>
  126 +
  127 +</RelativeLayout>
  128 +</layout>
0 \ No newline at end of file 129 \ No newline at end of file
app/src/main/res/layout/item.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<layout xmlns:android="http://schemas.android.com/apk/res/android">
  3 +
  4 + <data>
  5 +
  6 + <!--数据-->
  7 + <variable
  8 + name="data"
  9 + type="java.lang.Class"/>
  10 + <!--事件处理,例如点击事件-->
  11 + <variable
  12 + name="itemP"
  13 + type="java.lang.Class"/>
  14 + </data>
  15 +
  16 + <View
  17 + android:layout_width="match_parent"
  18 + android:layout_height="match_parent"/>
  19 +</layout>
  20 +