package com.akexorcist.sleepingforless.view.message;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.akexorcist.sleepingforless.R;
import com.akexorcist.sleepingforless.util.Utility;

/**
 * Created by Akexorcist on 3/25/2016 AD.
 */
public class MessageDialogFragment extends DialogFragment implements View.OnClickListener {
    private static final String KEY_MESSAGE = "key_message";

    private TextView tvDialogMessage;

    private OnDismissListener listener;
    private String message;

    public static MessageDialogFragment newInstance(String message) {
        MessageDialogFragment fragment = new MessageDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putString(KEY_MESSAGE, message);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.dialog_message, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        if (savedInstanceState == null) {
            message = getArguments().getString(KEY_MESSAGE);
        } else {
            message = savedInstanceState.getString(KEY_MESSAGE);
        }

        tvDialogMessage = (TextView) view.findViewById(R.id.tv_dialog_message);
        tvDialogMessage.setText(message);
        tvDialogMessage.setOnClickListener(this);
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        outState.putString(KEY_MESSAGE, message);
        super.onSaveInstanceState(outState);
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        super.onDismiss(dialog);
        if (listener != null) {
            listener.onDismiss();
        }
    }

    public void setOnDismissListener(OnDismissListener listener) {
        this.listener = listener;
    }

    @Override
    public void onClick(View v) {
        Utility.getInstance().copyTextToClipboard("Message", message);
        Snackbar.make(tvDialogMessage, R.string.copy_message_to_clipboard, Snackbar.LENGTH_SHORT).show();
    }

    public interface OnDismissListener {
        void onDismiss();
    }
}


@@ -470,16 +470,102 @@
 ility;%0A%0A
+import butterknife.Bind;%0Aimport butterknife.ButterKnife;%0Aimport butterknife.OnClick;%0A%0A
 /**%0A * C
@@ -668,40 +668,8 @@
 ent 
-implements View.OnClickListener 
 %7B%0A  
@@ -732,23 +732,49 @@
 %22;%0A%0A    
-private
+@Bind(R.id.tv_dialog_message)%0A   
  TextVie
@@ -797,24 +797,16 @@
 e;%0A%0A    
-private 
 OnDismis
@@ -829,24 +829,16 @@
 er;%0A    
-private 
 String m
@@ -1611,16 +1611,54 @@
 eState);
+%0A        ButterKnife.bind(this, view);
 %0A%0A      
@@ -1874,154 +1874,24 @@
 sage
- = (TextView) view.findViewById(R.id.tv_dialog_message);%0A        tvDialogMessage.setText(message);%0A        tvDialogMessage.setOnClickListener(this
+.setText(message
 );%0A 
@@ -2241,32 +2241,152 @@
        %7D%0A    %7D%0A%0A
+    @Override%0A    public void onDestroyView() %7B%0A        super.onDestroyView();%0A        ButterKnife.unbind(this);%0A    %7D%0A%0A
     public void 
@@ -2487,46 +2487,78 @@
   @O
-verride%0A    public void onClick(View v
+nClick(R.id.tv_dialog_message)%0A    public void copyMessageToClipboard(
 ) %7B%0A

Use ButterKnife