/**
 * The MIT License (MIT)
 * Copyright (c) 2012 David Carver
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
 * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package us.nineworlds.serenity.ui.browser.movie;

import com.jess.ui.TwoWayAdapterView;
import com.jess.ui.TwoWayAdapterView.OnItemSelectedListener;

import us.nineworlds.serenity.core.model.VideoContentInfo;
import us.nineworlds.serenity.R;

import android.app.Activity;
import android.os.Handler;
import android.view.View;
import android.widget.Spinner;
import android.widget.TextView;

/**
 * When a poster is selected, update the information displayed in the browser.
 * 
 * @author dcarver
 * 
 */
public class MovieGridPosterOnItemSelectedListener implements
		OnItemSelectedListener {

	private static Activity context;
	private View previous;
	private Handler subtitleHandler;
	private TwoWayAdapterView<?> adapter;

	/**
	 * 
	 */
	public MovieGridPosterOnItemSelectedListener(View bgv, Activity activity) {
		context = activity;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * android.widget.AdapterView.OnItemSelectedListener#onItemSelected(android
	 * .widget.AdapterView, android.view.View, int, long)
	 */
	@Override
	public void onItemSelected(TwoWayAdapterView<?> av, View v, int position,
			long id) {
		
		adapter = av;

		if (previous != null) {
			previous.setPadding(0, 0, 0, 0);
		}

		previous = v;

		v.setPadding(5, 5, 5, 5);

		createMovieMetaData();
	}


	private void createMovieMetaData() {
		
		VideoContentInfo mi = (VideoContentInfo) adapter.getSelectedItem();
		TextView subt = (TextView) context.findViewById(R.id.subtitleFilter);
		subt.setVisibility(View.GONE);
		Spinner subtitleSpinner = (Spinner) context.findViewById(R.id.videoSubtitle);
		subtitleSpinner.setVisibility(View.GONE);
		
		TextView posterTitle = (TextView) context.findViewById(R.id.movieBrowserPosterTitle);
		posterTitle.setText(mi.getTitle());
	}
	
	@Override
	public void onNothingSelected(TwoWayAdapterView<?> av) {
		if (previous != null) {
			previous.setPadding(0, 0, 0, 0);
			previous.refreshDrawableState();
		}

	}	
}

@@ -1200,100 +1200,33 @@
 ort 
-com.jess.ui.TwoWayAdapterView;%0Aimport com.jess.ui.TwoWayAdapterView.OnItemSelectedListener;%0A
+us.nineworlds.serenity.R;
 %0Aimp
@@ -1285,42 +1285,8 @@
 fo;%0A
-import us.nineworlds.serenity.R;%0A%0A
 impo
@@ -1314,35 +1314,8 @@
 ty;%0A
-import android.os.Handler;%0A
 impo
@@ -1400,16 +1400,116 @@
 tView;%0A%0A
+import com.jess.ui.TwoWayAdapterView;%0Aimport com.jess.ui.TwoWayAdapterView.OnItemSelectedListener;%0A%0A
 /**%0A * W
@@ -1766,42 +1766,8 @@
 us;%0A
-%09private Handler subtitleHandler;%0A
 %09pri
@@ -1924,181 +1924,8 @@
 %09%7D%0A%0A
-%09/*%0A%09 * (non-Javadoc)%0A%09 * %0A%09 * @see%0A%09 * android.widget.AdapterView.OnItemSelectedListener#onItemSelected(android%0A%09 * .widget.AdapterView, android.view.View, int, long)%0A%09 */%0A
 %09@Ov
@@ -2020,18 +2020,16 @@
 g id) %7B%0A
-%09%09
 %0A%09%09adapt
@@ -2180,17 +2180,16 @@
 ();%0A%09%7D%0A%0A
-%0A
 %09private
@@ -2218,18 +2218,16 @@
 ata() %7B%0A
-%09%09
 %0A%09%09Video
@@ -2431,32 +2431,37 @@
 Spinner) context
+%0A%09%09%09%09
 .findViewById(R.
@@ -2523,18 +2523,16 @@
 .GONE);%0A
-%09%09
 %0A%09%09TextV
@@ -2559,32 +2559,37 @@
 extView) context
+%0A%09%09%09%09
 .findViewById(R.
@@ -2658,17 +2658,16 @@
 ());%0A%09%7D%0A
-%09
 %0A%09@Overr
@@ -2833,12 +2833,11 @@
 %0A%09%09%7D%0A%0A%09%7D
-%09
 %0A%7D%0A

Remove some dead code.