Exemplo n.º 1
0
 public AniListActivityRecyclerAdapter(BaseAniDroidActivity context, IAniListActivityPresenter presenter,
                                       IAsyncEnumerable <OneOf <IPagedData <AniListActivity>, IAniListError> > enumerable, int?currentUserId) : base(context, enumerable, RecyclerCardType.Custom)
 {
     _presenter                  = presenter;
     _userId                     = currentUserId;
     _userNameColorHex           = $"#{Context.GetThemedColor(Resource.Attribute.Primary) & 0xffffff:X6}";
     _actionColorHex             = $"#{Context.GetThemedColor(Resource.Attribute.Primary_Dark) & 0xffffff:X6}";
     _defaultIconColor           = new Color(context.GetThemedColor(Resource.Attribute.Secondary_Dark));
     CustomCardUseItemDecoration = true;
 }
Exemplo n.º 2
0
 public AniListActivityRecyclerAdapter(BaseAniDroidActivity context, AniListActivityRecyclerAdapter adapter) :
     base(context, adapter)
 {
     _presenter                  = adapter._presenter;
     _userId                     = adapter._userId;
     _userNameColorHex           = $"#{Context.GetThemedColor(Resource.Attribute.Primary) & 0xffffff:X6}";
     _actionColorHex             = $"#{Context.GetThemedColor(Resource.Attribute.Primary_Dark) & 0xffffff:X6}";
     _defaultIconColor           = new Color(context.GetThemedColor(Resource.Attribute.Secondary_Dark));
     CustomCardUseItemDecoration = adapter.CustomCardUseItemDecoration;
 }
Exemplo n.º 3
0
 public AniListActivityRepliesRecyclerAdapter(BaseAniDroidActivity context, IAniListActivityPresenter presenter,
                                              List <AniListActivityReplyViewModel> items) : base(context, items, RecyclerCardType.Custom)
 {
     _presenter     = presenter;
     _userNameColor = new Color(Context.GetThemedColor(Resource.Attribute.Primary));
 }
Exemplo n.º 4
0
        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();
        }