public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.Inflate(Resource.Layout.SinglePostActivity, container, false); View toolbarLayout = view.FindViewById(Resource.Id.toolbarLayout); ImageView toolbarImageFarLeft = (ImageView)toolbarLayout.FindViewById(Resource.Id.toolbar_imageFarLeft); toolbarImageFarLeft.Visibility = ViewStates.Visible; Drawable backArrow = Context.Resources.GetDrawable(Resource.Drawable.abc_ic_ab_back_mtrl_am_alpha); backArrow.SetColorFilter(Resources.GetColor(Resource.Color.tenBlue), PorterDuff.Mode.SrcAtop); toolbarImageFarLeft.SetImageDrawable(backArrow); toolbarImageFarLeft.Click += (sender, e) => { FragmentManager.PopBackStack(); }; ImageView toolbarImageFarRight = (ImageView)toolbarLayout.FindViewById(Resource.Id.toolbar_imageFarRight); toolbarImageFarRight.Visibility = ViewStates.Visible; toolbarImageFarRight.SetImageResource(Resource.Drawable.actions); toolbarImageFarRight.Click += (sender, e) => { if (post.userPoster.IsMe() && post.isReposted == false) { Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(Context); alert.SetTitle(Strings.delete_post); alert.SetMessage(Strings.delete_post_confirm); alert.SetPositiveButton(Strings.delete, (senderAlert, args) => { DeletePost(); }); alert.SetNegativeButton(Strings.cancel, (senderAlert, args) => { }); alert.Show(); } else { Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(Context); alert.SetTitle(Strings.report_post); alert.SetMessage(Strings.report_post_confirm); alert.SetPositiveButton(Strings.report, (senderAlert, args) => { ReportPost(); }); alert.SetNegativeButton(Strings.cancel, (senderAlert, args) => { }); alert.Show(); } }; bottomView = view.FindViewById(Resource.Id.bottomView); SuggestionsLayout Suggestions = view.FindViewById<SuggestionsLayout>(Resource.Id.suggestionsLayout); Suggestions.InitView(); Suggestions.UserSelected += (User obj) => { inputField.AddUsername(obj.username); }; inputField = view.FindViewById<CharacterLimitedSuggestionEditText>(Resource.Id.inputField); inputField.BindDataToView(null, DealWithAddCommentButton, Activity, Suggestions); inputField.FocusDidChanged += (bool obj) => { ViewGroup.MarginLayoutParams para = (ViewGroup.MarginLayoutParams)((View)bottomView.Parent).LayoutParameters; if (obj) { para.BottomMargin = 0; } else { para.BottomMargin = ViewUtils.dpToPx(Activity, 50); } }; WebImage userimage = view.FindViewById<WebImage>(Resource.Id.userimage); userimage.BindDataToView(FragmentManager, Resource.Id.fragment_container_page, Globe.SharedInstance.User, false, false, null); addCommentButton = view.FindViewById<ImageButton>(Resource.Id.addCommentButton); addCommentButton.Click += async (sender, ev) => { string text = StringUtils.TrimWhiteSpaceAndNewLine(inputField.Text); if (!String.IsNullOrEmpty(text) && text != Strings.add_a_comment_placeholder) { addCommentButton.Enabled = false; ViewUtils.HideKeyboard(TabHostActivity.GetTabHost(), inputField); ProgressDialog progress = new ProgressDialog(Context); progress.Indeterminate = true; progress.SetProgressStyle(ProgressDialogStyle.Spinner); progress.SetMessage(Strings.adding_comment); progress.SetCancelable(false); progress.Show(); try { Comment res = await TenServices.AddComment(post, text); if (res != null) { if (CommentFeedFragment.TableItems.Count > 0 && CommentFeedFragment.TableItems[0].idComment == -1) { CommentFeedFragment.TableItems.RemoveAt(0); } CommentFeedFragment.TableItems.Add(res); CommentFeedFragment.ListViewAdapater.NotifyDataSetChanged(); CommentFeedFragment.ifFeedEmpty(); inputField.Text = ""; ViewUtils.HideKeyboard(TabHostActivity.GetTabHost(), inputField); ((View)inputField.Parent).RequestFocus(); CommentFeedFragment.HeaderFragment.HighlightCommentButton(); } } catch (RESTError e) { if (e.Message == "Invalid comment length") { FailBecauseCommentLength(); } } finally { addCommentButton.Enabled = true; progress.Dismiss(); } } }; CommentFeedFragment = new CommentFeedFragment(post); CommentFeedFragment.Master = this; CommentFeedFragment.EmptyTableString = Strings.no_comments; CommentFeedFragment.Target = FeedTypeEnum.FeedType.SinglePost; CommentFeedFragment.bottomView = bottomView; CommentFeedFragment.containerId = containerId; CommentFeedFragment.NewPageContainerID = Resource.Id.newpage_container; ChildFragmentManager.BeginTransaction().Add(Resource.Id.fragment_container, CommentFeedFragment).Commit(); return view; }
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; }