public async Task EditStatusActivityAsync(AniListActivity activity, int activityPosition, string updateText) { var postResp = await AniListService.SaveTextActivity(updateText, activity.Id, default); postResp.Switch((IAniListError error) => View.DisplaySnackbarMessage("Error occurred while saving status", Snackbar.LengthLong)) .Switch(updatedAct => View.UpdateActivity(activityPosition, updatedAct)); }
public async Task PostActivityReplyAsync(AniListActivity activity, int activityPosition, string text) { var postResp = await AniListService.PostActivityReply(activity.Id, text, default); postResp.Switch((IAniListError error) => { View.UpdateActivity(activityPosition, activity); View.DisplaySnackbarMessage("Error occurred while posting reply", Snackbar.LengthLong); }) .Switch(async reply => { var refreshResp = await AniListService.GetAniListActivityById(activity.Id, default); refreshResp.Switch((IAniListError error) => { View.UpdateActivity(activityPosition, activity); View.DisplaySnackbarMessage("Error occurred while refreshing activity", Snackbar.LengthLong); }) .Switch(activityResp => { View.UpdateActivity(activityPosition, activityResp); View.DisplaySnackbarMessage("Reply posted successfully", Snackbar.LengthShort); }); }); }
public async Task UpdateActivityAsync(AniListActivity activity, int activityPosition) { var activityResp = await AniListService.GetAniListActivityById(activity.Id, default); activityResp.Switch((IAniListError error) => View.DisplaySnackbarMessage("Error occurred while refreshing activity", Snackbar.LengthLong)) .Switch(updatedAct => View.UpdateActivity(activityPosition, updatedAct)); }
private static void PopulateLikesContainer(BaseAniDroidActivity context, AniListActivity activity, ViewGroup container) { var imageSize = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, context.Resources.DisplayMetrics); var padding = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 2, context.Resources.DisplayMetrics); var layoutParams = new ViewGroup.LayoutParams(imageSize, imageSize); var profileImages = activity.Likes.Select(x => { var image = new ImageView(context) { LayoutParameters = layoutParams }; image.SetPadding(padding, padding, padding, padding); ImageLoader.LoadImage(image, x.Avatar.Large); image.Click += (lSend, lArgs) => { UserActivity.StartActivity(context, x.Id); }; image.LongClick += (lSend, lArgs) => { Toast.MakeText(context, x.Name, ToastLength.Short).Show(); }; return(image); }).ToList(); container.Visibility = activity.Likes.Any() ? ViewStates.Visible : ViewStates.Gone; profileImages.ForEach(container.AddView); }
public async Task ToggleActivityLikeAsync(AniListActivity activity, int activityPosition) { var toggleResp = await AniListService.ToggleLike(activity.Id, LikeableType.Activity, default); toggleResp.Switch((IAniListError error) => { View.UpdateActivity(activityPosition, activity); View.DisplaySnackbarMessage("Error occurred while toggling like", Snackbar.LengthLong); }) .Switch(userLikes => { activity.Likes = userLikes; View.UpdateActivity(activityPosition, activity); }); }
public void UpdateActivity(int activityPosition, AniListActivity activity) { _userActivityRecyclerAdapter.Items[activityPosition] = activity; _userActivityRecyclerAdapter.NotifyItemChanged(activityPosition); }
public static void Create(BaseAniDroidActivity context, AniListActivity activity, int activityPosition, IAniListActivityPresenter activityPresenter, int?currentUserId, Action <int, string> replyAction, Action <int> likeAction) { var view = context.LayoutInflater.Inflate(Resource.Layout.Dialog_AniListActivityReply, null); var recycler = view.FindViewById <RecyclerView>(Resource.Id.AniListActivityReply_Recycler); var likesContainer = view.FindViewById <LinearLayout>(Resource.Id.AniListActivityReply_LikesContainer); var adapter = new AniListActivityRepliesRecyclerAdapter(context, activityPresenter, activity.Replies.Select(x => AniListActivityReplyViewModel.CreateViewModel(x, new Color(context.GetThemedColor(Resource.Attribute.Secondary_Dark)), currentUserId)).ToList()); var alert = new AlertDialog.Builder(context, context.GetThemedResourceId(Resource.Attribute.Dialog_Theme)); alert.SetView(view); var a = alert.Create(); adapter.LongClickAction = (viewModel, position) => { if (currentUserId.HasValue && viewModel.Model?.User?.Id == currentUserId) { CreateEditReply(context, viewModel.Model.Text, async text => { await activityPresenter.EditActivityReplyAsync(viewModel.Model, position, text); viewModel.RecreateViewModel(); adapter.NotifyItemChanged(position); a.Dismiss(); await activityPresenter.UpdateActivityAsync(activity, activityPosition); }, async() => { var resp = await activityPresenter.DeleteActivityReplyAsync(viewModel.Model, position); if (resp) { adapter.RemoveItem(position); } a.Dismiss(); await activityPresenter.UpdateActivityAsync(activity, activityPosition); }); } }; PopulateLikesContainer(context, activity, likesContainer); recycler.SetAdapter(adapter); a.SetButton((int)DialogButtonType.Negative, "Close", (send, args) => a.Dismiss()); if (currentUserId.HasValue) { var likeButtonText = activity.Likes?.Any(x => x.Id == currentUserId) == true ? "Unlike" : "Like"; a.SetButton((int)DialogButtonType.Neutral, likeButtonText, (send, args) => likeAction(activity.Id)); a.SetButton((int)DialogButtonType.Positive, "Submit", (send, args) => replyAction(activity.Id, view.FindViewById <EditText>(Resource.Id.AniListActivityReply_Reply).Text)); } else { view.FindViewById <EditText>(Resource.Id.AniListActivityReply_Reply).Visibility = ViewStates.Gone; } a.Show(); }