package com.sheep.gamegroup.view.activity;

import android.text.Html;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lqr.emoji.EmotionKeyboard;
import com.lqr.emoji.EmotionLayout;
import com.lqr.emoji.IEmotionSelectedListener;
import com.sheep.gamegroup.absBase.BaseActivity;
import com.sheep.gamegroup.util.DetailImageGetter;
import com.sheep.gamegroup.util.ViewUtil;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.utils.G;
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;

import java.util.Locale;

import butterknife.BindView;

/**
 * Created by realicing on 2018/11/7.
 * realicing@sina.com
 */
public class ActTestExpression extends BaseActivity {
    @BindView(R.id.test_content)
    TextView test_content;
    @BindView(R.id.test_input_comment)
    EditText mEtContent;
    @BindView(R.id.llContent)
    LinearLayout mLlContent;
    @BindView(R.id.elEmotion)
    EmotionLayout mElEmotion;

    private EmotionKeyboard mEmotionKeyboard;
    @Override
    protected int getLayoutId() {
        return R.layout.act_test_expression;
    }

    @Override
    public void initView() {
        TitleBarUtils.getInstance().setTitle(this, "写评价")
                .setEndTv(this, "发表", 0xFF2EBEF2, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        String content = mEtContent.getText().toString();
                        commitComment(content);
                    }
                })
                .setTitleFinish(this);
        initEmotionKeyboard();
        initSticker();
    }

    private void initSticker() {
        mElEmotion.attachEditText(mEtContent);

        mElEmotion.setEmotionSelectedListener(new IEmotionSelectedListener() {
            @Override
            public void onEmojiSelected(String key) {

            }

            @Override
            public void onStickerSelected(String categoryName, String stickerName, String stickerBitmapPath) {
                String stickerPath = stickerBitmapPath;
                G.shortToast(stickerPath);
            }
        });
    }

    private void initEmotionKeyboard() {
        mEmotionKeyboard = EmotionKeyboard.with(this);
        mEmotionKeyboard.bindToContent(mLlContent);
        mEmotionKeyboard.bindToEmotionButton(test_content);
        mEmotionKeyboard.bindToEditText(mEtContent);
        mEmotionKeyboard.setEmotionLayout(mElEmotion);
    }

    //提交数据
    private void commitComment(String content) {
        String msg = String.format(Locale.CHINA, "%s<img src=\"%s\" />", content, "exp_666");
        test_content.setText(Html.fromHtml(msg, new DetailImageGetter(test_content, msg, G.WIDTH), null));
    }

    //点击x来清空输入内容
    public void onClickXInput(View view) {
        ViewUtil.setText(test_content);
        ViewUtil.setText(mEtContent);
    }
}
