public void BindDataToView(TextView characterCountTextView, Action validate, Activity activity, SuggestionsLayout suggestionsView)
		{
			Validate = validate;
			CharacterCountTextView = characterCountTextView;
			Activity = activity;
			SuggestionsView = suggestionsView;
		}
Example #2
0
		public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
		{
			RelativeLayout view = (RelativeLayout)inflater.Inflate(Resource.Layout.PostActivity, container, false);
			view.Click += (sender, e) =>
			{
				ViewUtils.HideKeyboard(Activity, CaptionTextView);
				TabHostActivity.GetTabHost().ShowTabs();
			};

			Suggestions = view.FindViewById<SuggestionsLayout>(Resource.Id.suggestionsLayout);
			Suggestions.InitView();
			Suggestions.UserSelected += (User obj) =>
			{
				CaptionTextView.AddUsername(obj.username);
			};

			CharacterCountTextView = view.FindViewById<TextView>(Resource.Id.characterCount);

			CaptionTextView = view.FindViewById<CharacterLimitedSuggestionEditText>(Resource.Id.caption);
			CaptionTextView.BindDataToView(CharacterCountTextView, DealWithPostButton, Activity, Suggestions);

			PostButton = view.FindViewById<ImageButton>(Resource.Id.postbutton);
			PostButton.Click += async (object sender, EventArgs e) =>
			{
				string postText = StringUtils.TrimWhiteSpaceAndNewLine(CaptionTextView.Text);
				if (SelectedImage != null || (!String.IsNullOrEmpty(postText) && CaptionTextView.Text != Strings.add_a_caption_placeholder))
				{


					ProgressDialog progress = new ProgressDialog(Context);
					progress.Indeterminate = true;
					progress.SetProgressStyle(ProgressDialogStyle.Spinner);
					progress.SetMessage(Strings.posting);
					progress.SetCancelable(false);
					progress.Show();


					try
					{
						Byte[] myByteArray = null;
						if (SelectedImage != null)
						{
							MemoryStream stream = new MemoryStream();
							SelectedImage = ImageUtils.ReduceSizeIfNeededByWidth(SelectedImage, 1000);
							SelectedImage.Compress(Bitmap.CompressFormat.Jpeg, 80, stream);
							myByteArray = stream.ToArray();
						}
						Post result = await TenServices.Post(postText, myByteArray);

						progress.Dismiss();

						if (result != null)
						{
							FeedUtils.PassPostToAllFeedsIfExistsWithInclude(result, FeedTypeEnum.FeedType.HomeFeed);
							TabHostActivity.GetTabHost().tabHost.CurrentTab = 0;
							ViewUtils.HideKeyboard(TabHostActivity.GetTabHost(), CaptionTextView);
							ResetPage();
							ResetPostImageConstraints();
							TabHostActivity.GetTabHost().StartTickNotification();
						}
					}
					catch (RESTError error)
					{
						progress.Dismiss();
						Console.WriteLine(error.Message);
					}
				}
			};

			DeleteButton = view.FindViewById<ImageButton>(Resource.Id.delete);
			DeleteButton.BringToFront();
			DeleteButton.Click += (sender, e) =>
			{
				ResetPage();
			};

			ImageImageView = view.FindViewById<ImageView>(Resource.Id.image);


			LibraryButton = view.FindViewById<ImageButton>(Resource.Id.library);
			LibraryButton.Click += (sender, e) =>
			{
				Intent intent = new Intent();
				intent.SetType("image/*");
				intent.PutExtra(Intent.ExtraAllowMultiple, true);
				intent.SetAction(Intent.ActionGetContent);
				StartActivityForResult(Intent.CreateChooser(intent, "Select Picture"), 1);
			};
			CameraButton = view.FindViewById<ImageButton>(Resource.Id.camera);
			CameraButton.Click += (sender, e) =>
			{
				Android.Content.PM.PackageManager pm = Activity.PackageManager;
				if (pm.HasSystemFeature(Android.Content.PM.PackageManager.FeatureCamera))
				{
					TabHostActivity.GetTabHost().StopTickNotification();
					Intent intent = new Intent(Activity, typeof(CameraActivity));
					StartActivityForResult(intent, 2);
				}
				else {
					Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(Context);
					alert.SetTitle(Strings.error);
					alert.SetMessage("No Camera Found");
					alert.SetPositiveButton(Strings.ok, (senderAlert, args) => {});
					alert.Show();
				}
			};

			UsernameTextView = view.FindViewById<TextView>(Resource.Id.username);
			UserImageWebImage = view.FindViewById<WebImage>(Resource.Id.userimage);

			return view;
		}