/**
 * The MIT License (MIT)
 * Copyright (c) 2013 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 com.github.kingargyle.plexappclient.ui.browser.tv.episodes;

import com.github.kingargyle.plexappclient.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Gallery;

public class EpisodeBrowserActivity extends Activity {
	
	private Gallery posterGallery;
	private String key;
	private View bgLayout;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		key = getIntent().getExtras().getString("key");

		setContentView(R.layout.activity_movie_browser);
		
		
		bgLayout = findViewById(R.id.movieBrowserBackgroundLayout);
		
		posterGallery = (Gallery) findViewById(R.id.moviePosterGallery);
		posterGallery.setAdapter(new EpisodePosterImageGalleryAdapter(this, key));
		posterGallery.setOnItemSelectedListener(new EpisodePosterOnItemSelectedListener(bgLayout, this));
		posterGallery.setOnItemClickListener(new EpisodePosterOnItemClickListener());
		
		View l = findViewById(R.id.metaDataRow);
		l.setVisibility(View.INVISIBLE);
		
	}
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_movie_browser, menu);
		return true;
	}
	
	/* (non-Javadoc)
	 * @see android.app.Activity#onResume()
	 */
	@Override
	protected void onResume() {
		super.onResume();
		posterGallery.setAdapter(new EpisodePosterImageGalleryAdapter(this, key));
		posterGallery.setOnItemSelectedListener(new EpisodePosterOnItemSelectedListener(bgLayout, this));
		posterGallery.setOnItemClickListener(new EpisodePosterOnItemClickListener());		
	}
	
}

@@ -1526,16 +1526,82 @@
 gLayout;
+%0A%09private View metaData;%0A%09private boolean restarted_state = false;
 %0A%0A%09@Over
@@ -1803,14 +1803,8 @@
 r);%0A
-%09%09%0A%09%09%0A
 %09%09bg
@@ -1861,19 +1861,16 @@
 ayout);%0A
-%09%09%0A
 %09%09poster
@@ -1928,16 +1928,360 @@
 llery);%0A
+%09%09metaData = findViewById(R.id.metaDataRow);%0A%09%09metaData.setVisibility(View.INVISIBLE);%0A%09%09%09%09%0A%09%7D%0A%09%0A%09@Override%0A%09protected void onStart() %7B%0A%09%09super.onStart();%0A%09%09if (restarted_state == false) %7B%0A%09%09%09setupEpisodeBrowser();%0A%09%09%7D%0A%09%09restarted_state = false;%0A%09%7D%0A%0A%0A%09/**%0A%09 * Populate the episode browser with data%0A%09 */%0A%09protected void setupEpisodeBrowser() %7B%0A
 %09%09poster
@@ -2533,92 +2533,8 @@
 ));%0A
-%09%09%0A%09%09View l = findViewById(R.id.metaDataRow);%0A%09%09l.setVisibility(View.INVISIBLE);%0A%09%09%0A
 %09%7D%0A%09
@@ -2760,72 +2760,8 @@
 %7D%0A%09%0A
-%09/* (non-Javadoc)%0A%09 * @see android.app.Activity#onResume()%0A%09 */%0A
 %09@Ov
@@ -2788,19 +2788,20 @@
 id onRes
-ume
+tart
 () %7B%0A%09%09s
@@ -2814,277 +2814,46 @@
 nRes
-ume();%0A%09%09posterGallery.setAdapter(new EpisodePosterImageGalleryAdapter(this, key));%0A%09%09posterGallery.setOnItemSelectedListener(new EpisodePosterOnItemSelectedListener(bgLayout, this));%0A%09%09posterGallery.setOnItemClickListener(new EpisodePosterOnItemClickListener());%09%09
+tart();%0A%09%09restarted_state = true;
 %0A%09%7D%0A%09
+%09
 %0A%7D%0A

Update Episode Browser Activity