package com.dbs.mplus.knuh.customView;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.dbs.mplus.knuh.R;

public class NetworkErrorAlert extends Dialog {
  
  private static final String TAG = "NetworkErrorAlert";
  
  private Context context;
  
  private LinearLayout btnLayout;
  private Button btnConfirm2;
  private TextView tvAlertMsg;
  
  public NetworkErrorAlert(@NonNull Context context) {
    super(context);
    this.context = context;
  }
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    setCanceledOnTouchOutside(false);
    setContentView(R.layout.custom_alert);
    
    init();
  }
  
  private void init() {
    setLayout();
    setEvent();
  }
  
  private void setLayout() {
    btnLayout = (LinearLayout) findViewById(R.id.btnLayout);
    btnConfirm2 = (Button) findViewById(R.id.btnConfirm2);
    tvAlertMsg = (TextView) findViewById(R.id.tvAlertMsg);
    
    setCanceledOnTouchOutside(false); //화면 밖을 터치했을때 사라지지 않게
    
    Drawable confirmBg2 = (Drawable) btnConfirm2.getBackground();
    confirmBg2.setColorFilter(ContextCompat.getColor(context, R.color.alertConfirmColor), PorterDuff.Mode.SRC_ATOP);

    btnLayout.setVisibility(View.GONE);
    btnConfirm2.setVisibility(View.VISIBLE);
    
//    String message = String.format(context.getString(R.string.notEqualsSSID), Util.getSsidName());
    String message = context.getString(R.string.networkError);
    tvAlertMsg.setText(message);
  }
  
  private void setEvent() {
    btnConfirm2.setOnClickListener(onClickListener);
  }
  
  private View.OnClickListener onClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      dismiss();
    }
  };
  
  @Override
  public void show() {
    super.show();
  }
  
  @Override
  public void dismiss() {
    super.dismiss();
  }
  
}
