package com.android.chmo.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.android.chmo.R;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class ShareDialog extends Dialog {
    private OnShareListener onShareListener;

    public ShareDialog(@NonNull Context context) {
        super(context, R.style.DialogStyle);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_share);
        ButterKnife.bind(this);
        Window window = getWindow();
        WindowManager.LayoutParams wlp = window.getAttributes();
        wlp.gravity = Gravity.BOTTOM;
        window.setAttributes(wlp);
        window.setWindowAnimations(R.style.DialogAnimation);
        window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
    }

    @OnClick({R.id.ll_wechat_session, R.id.ll_wechat_timeline, R.id.tv_cancel})
    void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_wechat_session:
                if (onShareListener != null) {
                    onShareListener.onShareWechatSession();
                }
                dismiss();
                break;
            case R.id.ll_wechat_timeline:
                if (onShareListener != null) {
                    onShareListener.onShareWechatTimeline();
                }
                dismiss();
                break;
            case R.id.tv_cancel:
                dismiss();
                break;
        }
    }

    public void setOnShareListener(OnShareListener onShareListener) {
        this.onShareListener = onShareListener;
    }

    public interface OnShareListener {
        void onShareWechatSession();

        void onShareWechatTimeline();
    }
}
