//package com.kfzs.duanduan.fragment;
//
//import android.content.Intent;
//import android.os.Bundle;
//import android.text.TextUtils;
//import android.view.View;
//import android.widget.TextView;
//
//import com.kfzs.duanduan.BaseCompatFragment;
//import com.kfzs.duanduan.bean.KFIntentKeys;
//import com.kfzs.duanduan.bean.UserRecord;
//import com.kfzs.duanduan.bean.YinkerData;
//import com.sheep.gamegroup.model.entity.BaseMessage;
//import com.sheep.gamegroup.model.util.SheepSubscriber;
//import com.sheep.gamegroup.util.ActivityManager;
//import com.sheep.gamegroup.util.Jump2View;
//import com.sheep.gamegroup.view.activity.ActGuideDeblocked;
//import com.sheep.jiuyan.samllsheep.R;
//import com.sheep.jiuyan.samllsheep.SheepApp;
//import com.sheep.jiuyan.samllsheep.utils.G;
//import com.sheep.jiuyan.samllsheep.utils.SpUtils;
//
//import io.reactivex.android.schedulers.AndroidSchedulers;
//import io.reactivex.schedulers.Schedulers;
//
///**
// * 借着玩界面
// * Created by realicing on 2018/04/02.
// * realicing@sina.com
// */
//public class FgtBorrowPlay extends BaseCompatFragment{
//
//    private TextView fgt_bp_tv;
//    private boolean unbind_phone = true;//没有绑定手机号
//    private UserRecord userRecord;
//    @Override
//    protected void initView(Bundle savedInstanceState) {
//        setContentView(R.layout.fgt_bp);
//        fgt_bp_tv = getViewById(R.id.fgt_bp_tv);
//        fgt_bp_tv.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                boolean has_borrow = is(userRecord.getHave_access_state()) && !is(userRecord.getLoan_state());//已经借钱:借过款但是不允许借款
//                if(unbind_phone) {
//                } else if(userRecord == null){
//                    SpUtils.login(SheepApp.getInstance(),"");
//                    ActivityManager.getInstance().finishAllActivity();
//                    Jump2View.getInstance().goLoginView(SheepApp.getInstance(), "");
//                } else if(has_borrow){
//                    repay();
//                } else {
//                    borrow();
//                }
//            }
//        });
//        SheepApp.getInstance().getNetComponent().getApiService().userRecord()
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new SheepSubscriber<BaseMessage>(getContext()) {
//                    @Override
//                    public void onNext(BaseMessage baseMessage) {
//                        userRecord = baseMessage.getData(UserRecord.class);
//                        unbind_phone = false;
//                        boolean can_click = is(userRecord.getLoan_state()) || is(userRecord.getHave_access_state());//允许借款或者借过款就可以点击
//                        boolean has_open = is(userRecord.getHave_access_state());//已经开通:借过款就视为已经开通
//                        boolean has_borrow = is(userRecord.getHave_access_state()) && !is(userRecord.getLoan_state());//已经借钱:借过款但是不允许借款
//                        fgt_bp_tv.setText(getBtText(can_click, has_open, has_borrow));
//                    }
//
//                    @Override
//                    public void onError(BaseMessage baseMessage) {
//                        unbind_phone = "请绑定手机号".equals(baseMessage.getMsg());
//                    }
//                });
//    }
//    private String getBtText(boolean can_click,boolean has_open,boolean has_borrow) {
//        if(can_click){
//            if(unbind_phone){//没有绑定手机号
//                return "累计充值500立即开通";
//            } else if(!has_open){//没有开通情况
//                return "立即开通";
//            } else if (has_borrow){//已经借款情况
//                return "立即还款";
//            } else {
//                return "立即借款";
//            }
//        } else {
//            return "累计充值500立即开通";
//        }
//    }
//    private boolean is(int state){//Yes=1,No=2
//        return state == 1;
//    }
//    //还钱
//    private void repay(){
//        SheepApp.getInstance().getNetComponent().getApiService().getYinkerRepaymentUrl()
//                        .subscribeOn(Schedulers.io())
//                        .observeOn(AndroidSchedulers.mainThread())
//                        .subscribe(new SheepSubscriber<BaseMessage>(getContext()) {
//                            @Override
//                            public void onNext(BaseMessage baseMessage) {
//                                gotoUrl(baseMessage);
//                            }
//
//                            @Override
//                            public void onError(BaseMessage baseMessage) {
//                                G.showToast(baseMessage.getMsg());
//                            }
//                        });
//    }
//
//    private void gotoUrl(BaseMessage baseMessage) {
//        YinkerData yinkerData = baseMessage.getData(YinkerData.class);
//        if(yinkerData == null || TextUtils.isEmpty(yinkerData.getEntry_page_url())){
//            G.showToast(R.string.service_data_error);
//        } else {
//            Intent intent = new Intent(getActivity(), ActGuideDeblocked.class);
//            intent.putExtra(KFIntentKeys.EXTRA_WEBVIEW_URL, yinkerData.getEntry_page_url());
//            intent.putExtra(KFIntentKeys.EXTRA_WEBVIEW_TITLE, "借着玩");
//            startActivity(intent);
//        }
//    }
//
//    //借钱
//    private void borrow(){
//        SheepApp.getInstance().getNetComponent().getApiService().getYinkerLoanUrl()
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new SheepSubscriber<BaseMessage>(getContext()) {
//                    @Override
//                    public void onNext(BaseMessage baseMessage) {
//                        gotoUrl(baseMessage);
//                    }
//
//                    @Override
//                    public void onError(BaseMessage baseMessage) {
//                        G.showToast(baseMessage.getMsg());
//                    }
//                });
//    }
//
//}
