package com.vaguehope.onosendai.ui.pref;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.ToggleButton;

import com.vaguehope.onosendai.R;
import com.vaguehope.onosendai.config.NotificationStyle;
import com.vaguehope.onosendai.util.Titleable;

class NotificationStyleDialog implements Titleable {

	private final NotificationStyle initialValue;

	private final View llParent;
	private final ToggleButton chkNotify;
	private final CheckBox chkLights;
	private final CheckBox chkVibrate;
	private final CheckBox chkSound;

	public NotificationStyleDialog (final Context context, final NotificationStyle initialValue) {
		this.initialValue = initialValue;

		final LayoutInflater inflater = LayoutInflater.from(context);
		this.llParent = inflater.inflate(R.layout.notificationstyledialog, null);

		this.chkNotify = (ToggleButton) this.llParent.findViewById(R.id.chkNotify);
		this.chkLights = (CheckBox) this.llParent.findViewById(R.id.chkLights);
		this.chkVibrate = (CheckBox) this.llParent.findViewById(R.id.chkVibrate);
		this.chkSound = (CheckBox) this.llParent.findViewById(R.id.chkSound);

		this.chkNotify.setChecked(this.initialValue != null);
		this.chkNotify.setOnClickListener(this.chkNotifyClickListener);

		this.chkLights.setChecked(this.initialValue.isLights());
		this.chkVibrate.setChecked(this.initialValue.isVibrate());
		this.chkSound.setChecked(this.initialValue.isSound());
	}

	private final OnClickListener chkNotifyClickListener = new OnClickListener() {
		@Override
		public void onClick (final View v) {
			chkNotifyClick();
		}
	};

	protected void chkNotifyClick () {
		final boolean en = this.chkNotify.isChecked();
		this.chkLights.setEnabled(en);
		this.chkVibrate.setEnabled(en);
		this.chkSound.setEnabled(en);
	}

	@Override
	public String getUiTitle () {
		return "Notification Style";
	}

	public View getRootView () {
		return this.llParent;
	}

	public NotificationStyle getValue () {
		if (!this.chkNotify.isChecked()) return null;
		return new NotificationStyle(
				this.chkLights.isChecked(),
				this.chkVibrate.isChecked(),
				this.chkSound.isChecked());
	}

}

@@ -437,56 +437,8 @@
  %7B%0A%0A
-%09private final NotificationStyle initialValue;%0A%0A
 %09pri
@@ -463,16 +463,16 @@
 Parent;%0A
+
 %09private
@@ -708,45 +708,8 @@
 ) %7B%0A
-%09%09this.initialValue = initialValue;%0A%0A
 %09%09fi
@@ -1166,37 +1166,32 @@
 tify.setChecked(
-this.
 initialValue != 
@@ -1260,24 +1260,55 @@
 Listener);%0A%0A
+%09%09if (initialValue != null) %7B%0A%09
 %09%09this.chkLi
@@ -1315,37 +1315,32 @@
 ghts.setChecked(
-this.
 initialValue.isL
@@ -1347,24 +1347,25 @@
 ights());%0A%09%09
+%09
 this.chkVibr
@@ -1371,37 +1371,32 @@
 rate.setChecked(
-this.
 initialValue.isV
@@ -1406,16 +1406,17 @@
 ate());%0A
+%09
 %09%09this.c
@@ -1434,21 +1434,16 @@
 Checked(
-this.
 initialV
@@ -1455,24 +1455,28 @@
 isSound());%0A
+%09%09%7D%0A
 %09%7D%0A%0A%09private

Fix Singular Field. [sonar]