public IAsyncOperation <ContentDialogBaseResult> ShowAsync(AutoDownloadType flags)
        {
            CheckPhoto.IsChecked    = flags.HasFlag(AutoDownloadType.Photo);
            CheckAudio.IsChecked    = flags.HasFlag(AutoDownloadType.Audio);
            CheckRound.IsChecked    = flags.HasFlag(AutoDownloadType.Round);
            CheckVideo.IsChecked    = flags.HasFlag(AutoDownloadType.Video);
            CheckDocument.IsChecked = flags.HasFlag(AutoDownloadType.Document);
            CheckMusic.IsChecked    = flags.HasFlag(AutoDownloadType.Music);
            CheckGIF.IsChecked      = flags.HasFlag(AutoDownloadType.GIF);

            return(ShowAsync());
        }
        public override Task OnNavigatedToAsync(object parameter, NavigationMode navigationMode, IDictionary <string, object> state)
        {
            if (parameter is AutoDownloadType type)
            {
                _type = type;
                AutoDownloadMode mode;
                int limit;
                var preferences = Settings.AutoDownload;

                switch (type)
                {
                case AutoDownloadType.Photos:
                    Title  = Strings.Resources.AutoDownloadPhotos;
                    Header = Strings.Resources.AutoDownloadPhotosTitle;
                    mode   = preferences.Photos;
                    limit  = 0;
                    break;

                case AutoDownloadType.Videos:
                    Title  = Strings.Resources.AutoDownloadVideos;
                    Header = Strings.Resources.AutoDownloadVideosTitle;
                    mode   = preferences.Videos;
                    limit  = preferences.MaximumVideoSize;
                    break;

                case AutoDownloadType.VoiceMessages:
                    Title  = Strings.Resources.AudioAutodownload;
                    Header = Strings.Additional.AutoDownloadAudioTitle;
                    mode   = preferences.VoiceMessages;
                    limit  = 0;
                    break;

                case AutoDownloadType.Documents:
                default:
                    Title  = Strings.Resources.AutoDownloadFiles;
                    Header = Strings.Resources.AutoDownloadFilesTitle;
                    mode   = preferences.Documents;
                    limit  = preferences.MaximumDocumentSize;
                    break;
                }

                Contacts     = mode.HasFlag(AutoDownloadMode.WifiContacts);
                PrivateChats = mode.HasFlag(AutoDownloadMode.WifiPrivateChats);
                Groups       = mode.HasFlag(AutoDownloadMode.WifiGroups);
                Channels     = mode.HasFlag(AutoDownloadMode.WifiChannels);
                Limit        = limit;
            }

            return(Task.CompletedTask);
        }
Beispiel #3
0
        private string AppendFlag(AutoDownloadType flags, AutoDownloadType value, string text, string label)
        {
            if (flags.HasFlag(value))
            {
                if (text.Length > 0)
                {
                    text += ", ";
                }

                text += label;
            }

            return(text);
        }
Beispiel #4
0
        public override Task OnNavigatedToAsync(object parameter, NavigationMode navigationMode, IDictionary <string, object> state)
        {
            if (parameter is AutoDownloadType type)
            {
                _type = type;

                Title = type == AutoDownloadType.Photos
                    ? Strings.Resources.LocalPhotoCache
                    : type == AutoDownloadType.Videos
                    ? Strings.Resources.LocalVideoCache
                    : type == AutoDownloadType.Documents
                    ? Strings.Resources.FilesDataUsage
                    : type == AutoDownloadType.VideoNotes
                    ? Strings.Resources.VideoMessagesAutodownload
                    : type == AutoDownloadType.VoiceNotes
                    ? Strings.Resources.AudioAutodownload
                    : type == AutoDownloadType.Audios
                    ? Strings.Resources.LocalMusicCache
                    : Strings.Resources.LocalGifCache;

                var preferences = ProtoService.Preferences;
                var mode        = type == AutoDownloadType.Photos
                    ? preferences.Photos
                    : type == AutoDownloadType.Videos
                    ? preferences.Videos
                    : type == AutoDownloadType.Documents
                    ? preferences.Documents
                    : type == AutoDownloadType.VideoNotes
                    ? preferences.VideoNotes
                    : type == AutoDownloadType.VoiceNotes
                    ? preferences.VoiceNotes
                    : type == AutoDownloadType.Audios
                    ? preferences.Audios
                    : preferences.Animations;

                Contacts     = mode.HasFlag(AutoDownloadMode.WifiContacts);
                PrivateChats = mode.HasFlag(AutoDownloadMode.WifiPrivateChats);
                Groups       = mode.HasFlag(AutoDownloadMode.WifiGroups);
                Channels     = mode.HasFlag(AutoDownloadMode.WifiChannels);
            }

            return(Task.CompletedTask);
        }
Beispiel #5
0
        protected override Task OnNavigatedToAsync(object parameter, NavigationMode navigationMode, NavigationState state)
        {
            if (parameter is AutoDownloadType type)
            {
                _type = type;

                Title = type == AutoDownloadType.Photos
                    ? Strings.Resources.AutoDownloadPhotos
                    : type == AutoDownloadType.Videos
                    ? Strings.Resources.AutoDownloadVideos
                    : Strings.Resources.AutoDownloadFiles;
                Header = type == AutoDownloadType.Photos
                    ? Strings.Resources.AutoDownloadPhotosTitle
                    : type == AutoDownloadType.Videos
                    ? Strings.Resources.AutoDownloadVideosTitle
                    : Strings.Resources.AutoDownloadFilesTitle;

                var preferences = Settings.AutoDownload;
                var mode        = type == AutoDownloadType.Photos
                    ? preferences.Photos
                    : type == AutoDownloadType.Videos
                    ? preferences.Videos
                    : preferences.Documents;
                var limit = type == AutoDownloadType.Photos
                    ? 0
                    : type == AutoDownloadType.Videos
                    ? preferences.MaximumVideoSize
                    : preferences.MaximumDocumentSize;

                Contacts     = mode.HasFlag(AutoDownloadMode.WifiContacts);
                PrivateChats = mode.HasFlag(AutoDownloadMode.WifiPrivateChats);
                Groups       = mode.HasFlag(AutoDownloadMode.WifiGroups);
                Channels     = mode.HasFlag(AutoDownloadMode.WifiChannels);
                Limit        = limit;
            }

            return(Task.CompletedTask);
        }
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            var flags = (AutoDownloadType)0;

            if (CheckPhoto.IsChecked == true)
            {
                flags |= AutoDownloadType.Photo;
            }
            if (CheckAudio.IsChecked == true)
            {
                flags |= AutoDownloadType.Audio;
            }
            if (CheckRound.IsChecked == true)
            {
                flags |= AutoDownloadType.Round;
            }
            if (CheckVideo.IsChecked == true)
            {
                flags |= AutoDownloadType.Video;
            }
            if (CheckDocument.IsChecked == true)
            {
                flags |= AutoDownloadType.Document;
            }
            if (CheckMusic.IsChecked == true)
            {
                flags |= AutoDownloadType.Music;
            }
            if (CheckGIF.IsChecked == true)
            {
                flags |= AutoDownloadType.GIF;
            }

            SelectedItems = flags;
            Hide(ContentDialogBaseResult.OK);
        }
        private string ConvertAutoDownload(AutoDownloadType type, AutoDownloadMode mode, int limit)
        {
            int count   = 0;
            var builder = new StringBuilder();

            var mask = new int[4]
            {
                mode.HasFlag(AutoDownloadMode.WifiContacts) ? 0 : -1,
                mode.HasFlag(AutoDownloadMode.WifiPrivateChats) ? 1 : -1,
                mode.HasFlag(AutoDownloadMode.WifiGroups) ? 2 : -1,
                mode.HasFlag(AutoDownloadMode.WifiChannels) ? 3 : -1
            };

            for (int a = 0; a < mask.Length; a++)
            {
                if (mask[a] != -1)
                {
                    if (builder.Length != 0)
                    {
                        builder.Append(", ");
                    }
                    switch (a)
                    {
                    case 0:
                        builder.Append(Strings.Resources.AutoDownloadContacts);
                        break;

                    case 1:
                        builder.Append(Strings.Resources.AutoDownloadPm);
                        break;

                    case 2:
                        builder.Append(Strings.Resources.AutoDownloadGroups);
                        break;

                    case 3:
                        builder.Append(Strings.Resources.AutoDownloadChannels);
                        break;
                    }
                    count++;
                }
            }

            if (count == 4)
            {
                builder.Length = 0;

                if (type == AutoDownloadType.Photos)
                {
                    builder.Append(Strings.Resources.AutoDownloadOnAllChats);
                }
                else
                {
                    builder.AppendFormat(Strings.Resources.AutoDownloadUpToOnAllChats, FileSizeConverter.Convert(limit, true));
                }
            }
            else if (count == 0)
            {
                builder.Append(Strings.Resources.AutoDownloadOff);
            }
            else
            {
                if (type == AutoDownloadType.Photos)
                {
                    builder = new StringBuilder(string.Format(Strings.Resources.AutoDownloadOnFor, builder.ToString()));
                }
                else
                {
                    builder = new StringBuilder(string.Format(Strings.Resources.AutoDownloadOnUpToFor, FileSizeConverter.Convert(limit, true), builder.ToString()));
                }
            }

            return(builder.ToString());
        }
 public void AutoDownloadExecute(AutoDownloadType type)
 {
     NavigationService.Navigate(typeof(SettingsDataAutoPage), type);
 }
 public void Refresh()
 {
     Flags = ApplicationSettings.Current.AutoDownload[Type];
 }