Пример #1
0
        public bool ShouldDownload(AutoDownloadMode mode, AutoDownloadChat chat, NetworkType networkType)
        {
            bool isWiFi     = networkType is NetworkTypeWiFi;
            bool isCellular = !isWiFi && !(networkType is NetworkTypeNone);

            bool shouldDownload = false;

            switch (chat)
            {
            case AutoDownloadChat.Contact:
                if (isCellular)
                {
                    shouldDownload = (mode & AutoDownloadMode.CellularContacts) != 0;
                }
                else if (isWiFi)
                {
                    shouldDownload = (mode & AutoDownloadMode.WifiContacts) != 0;
                }
                break;

            case AutoDownloadChat.OtherPrivateChat:
                if (isCellular)
                {
                    shouldDownload = (mode & AutoDownloadMode.CellularPrivateChats) != 0;
                }
                else if (isWiFi)
                {
                    shouldDownload = (mode & AutoDownloadMode.WifiPrivateChats) != 0;
                }
                break;

            case AutoDownloadChat.Group:
                if (isCellular)
                {
                    shouldDownload = (mode & AutoDownloadMode.CellularGroups) != 0;
                }
                else if (isWiFi)
                {
                    shouldDownload = (mode & AutoDownloadMode.WifiGroups) != 0;
                }
                break;

            case AutoDownloadChat.Channel:
                if (isCellular)
                {
                    shouldDownload = (mode & AutoDownloadMode.CellularChannels) != 0;
                }
                else if (isWiFi)
                {
                    shouldDownload = (mode & AutoDownloadMode.WifiChannels) != 0;
                }
                break;

            default:
                break;
            }

            return(shouldDownload);
        }
Пример #2
0
        public AutoDownloadSettings UpdateDocumentsMode(AutoDownloadMode mode, long maximumSize)
        {
            var preferences = new AutoDownloadSettings();

            preferences._photos              = _photos;
            preferences._videos              = _videos;
            preferences._maximumVideoSize    = _maximumVideoSize;
            preferences._documents           = mode;
            preferences._maximumDocumentSize = maximumSize;
            return(preferences);
        }
Пример #3
0
        public AutoDownloadSettings UpdateVideosMode(AutoDownloadMode mode, int maximumSize)
        {
            var preferences = new AutoDownloadSettings();

            preferences._photos              = _photos;
            preferences._videos              = mode;
            preferences.VoiceMessages        = VoiceMessages;
            preferences._maximumVideoSize    = maximumSize;
            preferences._documents           = _documents;
            preferences._maximumDocumentSize = _maximumDocumentSize;
            return(preferences);
        }
Пример #4
0
        public AutoDownloadPreferences UpdateAnimationsMode(AutoDownloadMode mode)
        {
            var preferences = new AutoDownloadPreferences();

            preferences._photos              = _photos;
            preferences._videos              = _videos;
            preferences._maximumVideoSize    = _maximumVideoSize;
            preferences._documents           = _documents;
            preferences._maximumDocumentSize = _maximumDocumentSize;
            preferences._voiceNotes          = _voiceNotes;
            preferences._videoNotes          = _videoNotes;
            preferences._animations          = mode;
            return(preferences);
        }
        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());
        }