using System;

using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Util;
using PokktExtension;

namespace SampleApp.Droid
{
	[Activity (Label = "PokktSample", MainLauncher = true, Icon = "@drawable/icon")]
	public class MainActivity : Activity
	{
		string TAG = "PokktXamarinSample";
		private EditText editTextScreenName;

		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			//global::Xamarin.Forms.Forms.Init (this, bundle);

			//LoadApplication (new App ());

			SetContentView (Resource.Layout.main_screen_layout);

			// TODO: find a proper place for the following
			//PokktExtension.PokktManager.SetNativeExtentions(new AndroidExtension());

			editTextScreenName = (EditText)FindViewById(Resource.Id.editScreenName);

			String versionName = "v";
			try {

				versionName += PackageManager.GetPackageInfo(PackageName , 0).VersionCode;
				Log.Debug(TAG, "Version No: "+versionName);
			} catch (Exception e) {
				Log.Debug (TAG, e.Message);
			}

			((TextView) FindViewById(Resource.Id.tvVersion)).Text = versionName;

			//Offerwall
			Button btnOfferwall = FindViewById<Button> (Resource.Id.button_offerwall);
			btnOfferwall.Click += delegate 
			{
				StartActivity(new Intent(this, typeof(OfferwallActivity)));
			};

			//Video : Rewarded Ad
			Button btnVideo = FindViewById<Button> (Resource.Id.button_rewarded_ad);
			btnVideo.Click += delegate 
			{
				if (editTextScreenName.Text.Length > 0) {
					Intent intent = new Intent(this, typeof(VideoActivity));
					intent.PutExtra("isRewarded", true);
					intent.PutExtra("screenName", editTextScreenName.Text.ToString().Trim());
					StartActivity(intent);
				} else {
					Toast.MakeText(this, "", ToastLength.Long).Show();
				}
			};

			//Video : Non-Rewarded Ad
			Button btnVideoNoAuto = FindViewById<Button> (Resource.Id.button_no_rewarded);
			btnVideoNoAuto.Click += delegate 
			{
				if (editTextScreenName.Text.Length > 0) {
					Intent intent = new Intent(this, typeof(VideoActivity));
					intent.PutExtra("isRewarded", false);
					intent.PutExtra("screenName", editTextScreenName.Text.ToString().Trim());
					StartActivity(intent);
				} else {
					Toast.MakeText(this, "", ToastLength.Long).Show();
				}
			};

			FindViewById<Button> (Resource.Id.button_export_log).Click += delegate 
			{
				//PokktManagerHandler.ExportLog();
			};
		}
	}
}
