package com.sheep.gamegroup.view.activity;

import android.support.design.widget.TextInputEditText;
import android.view.View;
import android.widget.ImageView;

import com.alibaba.fastjson.JSONObject;
import com.sheep.gamegroup.absBase.BaseActivity;
import com.sheep.gamegroup.model.entity.BaseMessage;
import com.sheep.gamegroup.model.util.SheepSubscriber;
import com.sheep.gamegroup.util.ApiUtil;
import com.sheep.gamegroup.util.QQUtil;
import com.sheep.gamegroup.util.ViewUtil;
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.TitleBarUtils;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import io.reactivex.schedulers.Schedulers;

import static com.sheep.gamegroup.util.UMConfigUtils.Event.USER_FEEDBACK_COMMIT;

/**
 * 意见反馈
 * Created by ljy on 2018/5/10.
 */

public class FeedbackAct extends BaseActivity {
    @BindView(R.id.feedbook_et)
    TextInputEditText feedbookEt;
    @BindView(R.id.feedbook_email_et)
    TextInputEditText feedbookEmailEt;
    @BindView(R.id.feedbook_qq_et)
    TextInputEditText feedbook_qq_et;
    @BindView(R.id.contact_qq_iv)
    ImageView contact_qq_iv;

    private String Content;
    private String Email;
    private String qq;

    @Override
    protected int getLayoutId() {
        return R.layout.act_feedback_layout;
    }

    @Override
    public void initView() {
        TitleBarUtils.getInstance()
                .setShowOrHide(this, true)
                .setTitle(this, "意见反馈")
                .setTitleFinish(this);
    }

    @Override
    public void initListener() {
        ViewUtil.setImage(contact_qq_iv, ViewUtil.getNetImgByName("ic_contact_qq"));
    }

    @Override
    public void initData() {

    }

    @OnClick(R.id.tv_submit)
    public void onViewClicked() {
        USER_FEEDBACK_COMMIT.onEvent();
        Content = feedbookEt.getText() + "";
        Email = feedbookEmailEt.getText() + "";
        qq = feedbook_qq_et.getText() + "";
        if (android.text.TextUtils.isEmpty(Content)) {
            G.showToast(getResources().getString(R.string.feedback_notice_input_advice));
            return;
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("Content", Content);
        jsonObject.put("Email", Email + "");
        jsonObject.put("QQ", qq + "");
        SheepApp.getInstance()
                .getNetComponent()
                .getApiService()
                .feedback(jsonObject)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SheepSubscriber<BaseMessage>(this) {
                    @Override
                    public void onError(BaseMessage baseMessage) {
                        G.showToast(baseMessage);
                    }

                    @Override
                    public void onNext(BaseMessage baseMessage) {
                        G.showToast("反馈成功");
                        finish();
                    }
                });
    }

    //点击联系qq
    public void onClickContactQQ(View view) {
        ApiUtil.getNewAboutUsComplainQq(new Action1<String>() {
            @Override
            public void call(String qq) {
                QQUtil.skip3(FeedbackAct.this, qq);
            }
        });
    }
}
