Esempio n. 1
0
        protected override void OnStart()
        {
            try
            {
                base.OnStart();

                IMethods.Set_TextViewIcon("1", BackIcon, IonIcons_Fonts.AndroidArrowBack);

                //profile_picture
                ImageCacheLoader.LoadImage(UserDetails.avatar, UserProfileImage, false, true);

                if (!string.IsNullOrEmpty(UserDetails.Full_name))
                {
                    usernameText.Text = UserDetails.Full_name;
                }
                else
                {
                    usernameText.Text = UserDetails.Username;
                }

                ActivityListItems.Clear();

                if (Type == "image")
                {
                    SetImageStory(Uri);
                }
                else
                {
                    SetvideoStory(Uri);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 2
0
        //Event Click Add Story
        public void OnClick(View v)
        {
            try
            {
                if (IMethods.CheckConnectivity())
                {
                    if (Type == "image")
                    {
                        //Send image function
                        var file = Android.Net.Uri.FromFile(new File(Uri));
                        PikedImage = IMethods.Fun_String.TrimTo(file.Path.Split('/').Last(), 30);
                        var stream = IMethods.MultiMedia.GetMedia_as_Stream(file.Path);

                        var check = ActivityListItems.FirstOrDefault(a => a.Label == PikedImage);
                        if (check == null)
                        {
                            ActivityListItems.Add(new Classes.Storyitems
                            {
                                Label         = PikedImage,
                                ImageFullPath = file.Path,
                                ImageStream   = stream
                            });
                        }

                        var attach = ActivityListItems.FirstOrDefault(a => a.Label == PikedImage);
                        if (attach != null)
                        {
                            List <Stream> streams = new List <Stream>();

                            foreach (var Atta in ActivityListItems)
                            {
                                if (Atta.ImageStream != null)
                                {
                                    streams.Add(Atta.ImageStream);
                                }
                            }

                            unixTimestamp = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                            Time          = Convert.ToString(unixTimestamp);

                            List <GetStoriesObject.Story> listOfStories = new List <GetStoriesObject.Story>();
                            var checkUser =
                                Last_Stroies_Fragment.StoryAdapter?.mStoryList?.FirstOrDefault(a =>
                                                                                               a.user_id == UserDetails.User_id);
                            if (checkUser != null)
                            {
                                var checkUserExits =
                                    Classes.StoryList.FirstOrDefault(a => a.Value == checkUser.user_id);
                                if (checkUserExits.Value == null)
                                {
                                    var ch = checkUserExits.Key?.FirstOrDefault(a => a.id == checkUser.id);
                                    if (ch == null)
                                    {
                                        GetStoriesObject.Story story = new GetStoriesObject.Story
                                        {
                                            user_data = new GetStoriesObject.UserData()
                                            {
                                                name = !string.IsNullOrEmpty(UserDetails.Full_name)
                                                    ? UserDetails.Full_name
                                                    : UserDetails.Username,
                                                avatar = UserDetails.avatar,
                                            },
                                            thumbnail   = file.Path,
                                            id          = Time,
                                            user_id     = UserDetails.User_id,
                                            title       = Txt_AboutStory.MessageText,
                                            description = Txt_AboutStory.MessageText,
                                            is_owner    = true,
                                            type        = "image",
                                        };

                                        listOfStories.Add(story);

                                        Classes.StoryList.Add(listOfStories, story.user_id);
                                    }
                                }
                                else
                                {
                                    foreach (var item in Classes.StoryList.Keys.ToList())
                                    {
                                        string userId = item.FirstOrDefault(a => a.user_id == checkUser.user_id)
                                                        ?.user_id;

                                        if (checkUserExits.Value == userId)
                                        {
                                            GetStoriesObject.Story story = new GetStoriesObject.Story
                                            {
                                                user_data = new GetStoriesObject.UserData()
                                                {
                                                    name = !string.IsNullOrEmpty(UserDetails.Full_name)
                                                        ? UserDetails.Full_name
                                                        : UserDetails.Username,
                                                    avatar = UserDetails.avatar,
                                                },
                                                thumbnail   = file.Path,
                                                id          = Time,
                                                user_id     = UserDetails.User_id,
                                                title       = Txt_AboutStory.MessageText,
                                                description = Txt_AboutStory.MessageText,
                                                is_owner    = true,
                                                type        = "image",
                                            };

                                            var ch = item.FirstOrDefault(a => a.id == story.id);
                                            if (ch == null)
                                            {
                                                item.Add(story);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                GetStoriesObject.Story story = new GetStoriesObject.Story
                                {
                                    user_data = new GetStoriesObject.UserData()
                                    {
                                        name = !string.IsNullOrEmpty(UserDetails.Full_name)
                                            ? UserDetails.Full_name
                                            : UserDetails.Username,
                                        avatar = UserDetails.avatar,
                                    },
                                    thumbnail   = file.Path,
                                    id          = Time,
                                    user_id     = UserDetails.User_id,
                                    title       = Txt_AboutStory.MessageText,
                                    description = Txt_AboutStory.MessageText,
                                    is_owner    = true,
                                    type        = "image",
                                };

                                Last_Stroies_Fragment.StoryAdapter?.Add(story);

                                listOfStories.Clear();

                                var checkUserExits = Classes.StoryList.FirstOrDefault(a => a.Value == story.user_id);
                                if (checkUserExits.Value == null)
                                {
                                    listOfStories.Add(story);
                                    Classes.StoryList.Add(listOfStories, story.user_id);
                                }
                            }

                            Task.Factory.StartNew(async() =>
                            {
                                //just pass file_path and type video or image

                                var(Api_status, Respond) = await WoWonder_API.Requests.RequestsAsync.Story.Create_Story(Txt_AboutStory.MessageText,
                                                                                                                        "", file.Path, "image");
                                if (Api_status == 200)
                                {
                                    if (Respond is CreateStoryObject result)
                                    {
                                        Console.WriteLine(result.story_id);

                                        Toast.MakeText(this, GetText(Resource.String.Lbl_Done), ToastLength.Short)
                                        .Show();
                                    }
                                }
                                else
                                {
                                    Toast.MakeText(this, GetText(Resource.String.Lbl_Something_went_wrong),
                                                   ToastLength.Short).Show();
                                }
                            });
                            Finish();
                        }
                    }
                    else
                    {
                        VideoTimer.Enabled = false;
                        VideoTimer.Stop();

                        //Send image function
                        var file = Android.Net.Uri.FromFile(new File(Uri));

                        List <GetStoriesObject.Story> listOfStories = new List <GetStoriesObject.Story>();

                        var checkUser =
                            Last_Stroies_Fragment.StoryAdapter?.mStoryList?.FirstOrDefault(a =>
                                                                                           a.user_id == UserDetails.User_id);
                        if (checkUser != null)
                        {
                            if (Classes.StoryList == null)
                            {
                                return;
                            }

                            var checkUserExits = Classes.StoryList.FirstOrDefault(a => a.Value == checkUser.user_id);
                            if (checkUserExits.Value == null)
                            {
                                var ch = checkUserExits.Key.FirstOrDefault(a => a.id == checkUser.id);
                                if (ch == null)
                                {
                                    GetStoriesObject.Story story = new GetStoriesObject.Story
                                    {
                                        user_data = new GetStoriesObject.UserData()
                                        {
                                            name = !string.IsNullOrEmpty(UserDetails.Full_name)
                                                ? UserDetails.Full_name
                                                : UserDetails.Username,
                                            avatar = UserDetails.avatar,
                                        },
                                        thumbnail   = file.Path,
                                        id          = Time,
                                        user_id     = UserDetails.User_id,
                                        title       = Txt_AboutStory.MessageText,
                                        description = Txt_AboutStory.MessageText,
                                        is_owner    = true,
                                        type        = "video",
                                    };

                                    listOfStories.Add(story);

                                    Classes.StoryList.Add(listOfStories, story.user_id);
                                }
                            }
                            else
                            {
                                if (Classes.StoryList == null)
                                {
                                    return;
                                }

                                foreach (var item in Classes.StoryList?.Keys.ToList())
                                {
                                    string userId = item.FirstOrDefault(a => a.user_id == checkUser.user_id)?.user_id;
                                    if (checkUserExits.Value == userId)
                                    {
                                        GetStoriesObject.Story story = new GetStoriesObject.Story
                                        {
                                            user_data = new GetStoriesObject.UserData()
                                            {
                                                name = !string.IsNullOrEmpty(UserDetails.Full_name)
                                                    ? UserDetails.Full_name
                                                    : UserDetails.Username,
                                                avatar = UserDetails.avatar,
                                            },
                                            thumbnail   = file.Path,
                                            id          = Time,
                                            user_id     = UserDetails.User_id,
                                            title       = Txt_AboutStory.MessageText,
                                            description = Txt_AboutStory.MessageText,
                                            is_owner    = true,
                                            type        = "video",
                                        };

                                        var ch = item.FirstOrDefault(a => a.id == story.id);
                                        if (ch == null)
                                        {
                                            item.Add(story);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            GetStoriesObject.Story story = new GetStoriesObject.Story
                            {
                                user_data = new GetStoriesObject.UserData()
                                {
                                    name = !string.IsNullOrEmpty(UserDetails.Full_name)
                                        ? UserDetails.Full_name
                                        : UserDetails.Username,
                                    avatar = UserDetails.avatar,
                                },
                                thumbnail   = file.Path,
                                id          = Time,
                                user_id     = UserDetails.User_id,
                                title       = Txt_AboutStory.MessageText,
                                description = Txt_AboutStory.MessageText,
                                is_owner    = true,
                                type        = "video",
                            };

                            Last_Stroies_Fragment.StoryAdapter?.Add(story);

                            listOfStories.Clear();

                            var checkUserExits = Classes.StoryList.FirstOrDefault(a => a.Value == story.user_id);
                            if (checkUserExits.Value == null)
                            {
                                listOfStories.Add(story);
                                Classes.StoryList.Add(listOfStories, story.user_id);
                            }
                        }

                        Task.Factory.StartNew(async() =>
                        {
                            //just pass file_path and type video or image
                            var(Api_status, Respond) = await WoWonder_API.Requests.RequestsAsync.Story.Create_Story(Txt_AboutStory.MessageText,
                                                                                                                    "", file.Path, "video");
                            if (Api_status == 200)
                            {
                                if (Respond is CreateStoryObject result)
                                {
                                    Console.WriteLine(result.story_id);

                                    var getStory =
                                        Classes.StoryList.FirstOrDefault(a => a.Value == UserDetails.User_id);
                                    if (getStory.Value != null)
                                    {
                                        var dataStory = getStory.Key.FirstOrDefault(a => a.id == Time);
                                        if (dataStory != null)
                                        {
                                            dataStory.id = result.story_id.ToString();
                                        }
                                    }

                                    Toast.MakeText(this, GetText(Resource.String.Lbl_Done), ToastLength.Short).Show();
                                }
                            }
                            else
                            {
                                Toast.MakeText(this, GetText(Resource.String.Lbl_Something_went_wrong),
                                               ToastLength.Short).Show();
                            }
                        });

                        Finish();
                    }
                }
                else
                {
                    Toast.MakeText(this, GetText(Resource.String.Lbl_Error_check_internet_connection),
                                   ToastLength.Short)
                    .Show();
                }

                Finish();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 3
0
        protected override void OnStart()
        {
            try
            {
                base.OnStart();

                IMethods.Set_TextViewIcon("1", BackIcon, IonIcons_Fonts.AndroidArrowBack);

                //profile_picture
                var AvatarSplit = UserDetails.avatar.Split('/').Last();
                if (AvatarSplit == "d-avatar.jpg")
                {
                    var ImageTrancform = ImageService.Instance.LoadUrl("no_profile_image.png");
                    ImageTrancform.LoadingPlaceholder("no_profile_image.png", ImageSource.CompiledResource);
                    ImageTrancform.ErrorPlaceholder("no_profile_image.png", ImageSource.CompiledResource);
                    ImageTrancform.TransformPlaceholders(true);
                    ImageTrancform.Transform(new CircleTransformation(5, "#ffffff"));
                    ImageTrancform.Into(UserProfileImage);
                }
                else
                {
                    var GetImg = IMethods.MultiMedia.GetMediaFrom_Disk(IMethods.IPath.FolderDiskImage, AvatarSplit);
                    if (GetImg == "File Dont Exists")
                    {
                        Task.Run(() =>
                        {
                            IMethods.MultiMedia.DownloadMediaTo_DiskAsync(IMethods.IPath.FolderDiskImage,
                                                                          UserDetails.avatar);
                            IMethods.Load_Image_From_Url(UserProfileImage, UserDetails.avatar);
                        });
                    }
                    else
                    {
                        var file           = Android.Net.Uri.FromFile(new File(GetImg));
                        var ImageTrancform = ImageService.Instance.LoadFile(file.Path);
                        ImageTrancform.LoadingPlaceholder("no_profile_image.png", ImageSource.CompiledResource);
                        ImageTrancform.ErrorPlaceholder("no_profile_image.png", ImageSource.CompiledResource);
                        ImageTrancform.TransformPlaceholders(true);
                        ImageTrancform.Transform(new CircleTransformation(5, "#ffffff"));
                        ImageTrancform.FadeAnimation(false);
                        ImageTrancform.Into(UserProfileImage);
                    }
                }

                if (!string.IsNullOrEmpty(UserDetails.Full_name))
                {
                    usernameText.Text = UserDetails.Full_name;
                }
                else
                {
                    usernameText.Text = UserDetails.Username;
                }

                Txt_AboutStory.SetMessageBoxHint("Add caption");
                Txt_AboutStory.SetSendClickListener(this);

                ActivityListItems.Clear();

                if (Type == "image")
                {
                    SetImageStory(Uri);
                }
                else
                {
                    SetvideoStory(Uri);
                }
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
            }
        }