Java Code Examples for org.telegram.messenger.FileLoader#getAttachFileName()

The following examples show how to use org.telegram.messenger.FileLoader#getAttachFileName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockingUpdateView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void show(int account, TLRPC.TL_help_appUpdate update) {
    pressCount = 0;
    appUpdate = update;
    accountNum = account;
    if (update.document instanceof TLRPC.TL_document) {
        fileName = FileLoader.getAttachFileName(update.document);
    }
    if (getVisibility() != VISIBLE) {
        setVisibility(VISIBLE);
    }
    SpannableStringBuilder builder = new SpannableStringBuilder(update.text);
    MessageObject.addEntitiesToText(builder, update.entities, false, 0, false, false, false);
    textView.setText(builder);
    if (update.document instanceof TLRPC.TL_document) {
        acceptTextView.setText(LocaleController.getString("Update", R.string.Update).toUpperCase() + String.format(Locale.US, " (%1$s)", AndroidUtilities.formatFileSize(update.document.size)));
    } else {
        acceptTextView.setText(LocaleController.getString("Update", R.string.Update).toUpperCase());
    }
    NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileDidLoaded);
    NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileDidFailedLoad);
    NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileLoadProgressChanged);
}
 
Example 2
Source File: BlockingUpdateView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void show(int account, TLRPC.TL_help_appUpdate update) {
    pressCount = 0;
    appUpdate = update;
    accountNum = account;
    if (update.document instanceof TLRPC.TL_document) {
        fileName = FileLoader.getAttachFileName(update.document);
    }
    if (getVisibility() != VISIBLE) {
        setVisibility(VISIBLE);
    }
    SpannableStringBuilder builder = new SpannableStringBuilder(update.text);
    MessageObject.addEntitiesToText(builder, update.entities, false, 0, false, false, false);
    textView.setText(builder);
    if (update.document instanceof TLRPC.TL_document) {
        acceptTextView.setText(LocaleController.getString("Update", R.string.Update).toUpperCase() + String.format(Locale.US, " (%1$s)", AndroidUtilities.formatFileSize(update.document.size)));
    } else {
        acceptTextView.setText(LocaleController.getString("Update", R.string.Update).toUpperCase());
    }
    NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileDidLoaded);
    NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileDidFailedLoad);
    NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileLoadProgressChanged);
}
 
Example 3
Source File: OtherDocumentPlaceholderDrawable.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void checkFileExist() {
    if (parentMessageObject != null && parentMessageObject.messageOwner.media != null) {
        String fileName = null;
        File cacheFile;
        if (TextUtils.isEmpty(parentMessageObject.messageOwner.attachPath) || !(new File(parentMessageObject.messageOwner.attachPath).exists())) {
            cacheFile = FileLoader.getPathToMessage(parentMessageObject.messageOwner);
            if (!cacheFile.exists()) {
                fileName = FileLoader.getAttachFileName(parentMessageObject.getDocument());
            }
        }
        loaded = false;
        if (fileName == null) {
            progressVisible = false;
            loading = false;
            loaded = true;
            DownloadController.getInstance(parentMessageObject.currentAccount).removeLoadingFileObserver(this);
        } else {
            DownloadController.getInstance(parentMessageObject.currentAccount).addLoadingFileObserver(fileName, this);
            loading = FileLoader.getInstance(parentMessageObject.currentAccount).isLoadingFile(fileName);
            if (loading) {
                progressVisible = true;
                Float progress = ImageLoader.getInstance().getFileProgress(fileName);
                if (progress == null) {
                    progress = 0.0f;
                }
                setProgress(progress, false);
            } else {
                progressVisible = false;
            }
        }
    } else {
        loading = false;
        loaded = true;
        progressVisible = false;
        setProgress(0, false);
        DownloadController.getInstance(parentMessageObject.currentAccount).removeLoadingFileObserver(this);
    }
    parentView.invalidate();
}
 
Example 4
Source File: ThemesHorizontalListCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    Theme.ThemeInfo t = currentType == ThemeActivity.THEME_TYPE_NIGHT ? Theme.getCurrentNightTheme() : Theme.getCurrentTheme();
    button.setChecked(themeInfo == t, false);
    if (themeInfo != null && themeInfo.info != null && !themeInfo.themeLoaded) {
        String name = FileLoader.getAttachFileName(themeInfo.info.document);
        if (!loadingThemes.containsKey(name) && !loadingWallpapers.containsKey(themeInfo)) {
            themeInfo.themeLoaded = true;
            placeholderAlpha = 0.0f;
            parseTheme();
            applyTheme();
        }
    }
}
 
Example 5
Source File: ThemesHorizontalListCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void setTheme(Theme.ThemeInfo theme, boolean last, boolean first) {
    themeInfo = theme;
    isFirst = first;
    isLast = last;
    accentId = theme.currentAccentId;
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) button.getLayoutParams();
    layoutParams.leftMargin = AndroidUtilities.dp(isFirst ? 22 + 27 : 27);
    button.setLayoutParams(layoutParams);
    placeholderAlpha = 0.0f;

    if (themeInfo.pathToFile != null && !themeInfo.previewParsed) {
        themeInfo.setPreviewInColor(Theme.getDefaultColor(Theme.key_chat_inBubble));
        themeInfo.setPreviewOutColor(Theme.getDefaultColor(Theme.key_chat_outBubble));
        File file = new File(themeInfo.pathToFile);
        boolean fileExists = file.exists();
        boolean parsed = fileExists && parseTheme();
        if ((!parsed || !fileExists) && themeInfo.info != null) {
            if (themeInfo.info.document != null) {
                themeInfo.themeLoaded = false;
                placeholderAlpha = 1.0f;
                loadingDrawable = getResources().getDrawable(R.drawable.msg_theme).mutate();
                Theme.setDrawableColor(loadingDrawable, loadingColor = Theme.getColor(Theme.key_windowBackgroundWhiteGrayText7));
                if (!fileExists) {
                    String name = FileLoader.getAttachFileName(themeInfo.info.document);
                    if (!loadingThemes.containsKey(name)) {
                        loadingThemes.put(name, themeInfo);
                        FileLoader.getInstance(themeInfo.account).loadFile(themeInfo.info.document, themeInfo.info, 1, 1);
                    }
                }
            } else {
                loadingDrawable = getResources().getDrawable(R.drawable.preview_custom).mutate();
                Theme.setDrawableColor(loadingDrawable, loadingColor = Theme.getColor(Theme.key_windowBackgroundWhiteGrayText7));
            }
        }
    }
    applyTheme();
}
 
Example 6
Source File: SharedDocumentCell.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void updateFileExistIcon() {
    if (message != null && message.messageOwner.media != null) {
        loaded = false;
        if (message.attachPathExists || message.mediaExists) {
            statusImageView.setVisibility(INVISIBLE);
            progressView.setVisibility(INVISIBLE);
            dateTextView.setPadding(0, 0, 0, 0);
            loading = false;
            loaded = true;
            DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
        } else {
            String fileName = FileLoader.getAttachFileName(message.getDocument());
            DownloadController.getInstance(currentAccount).addLoadingFileObserver(fileName, message, this);
            loading = FileLoader.getInstance(currentAccount).isLoadingFile(fileName);
            statusImageView.setVisibility(VISIBLE);
            statusImageView.setImageResource(loading ? R.drawable.media_doc_pause : R.drawable.media_doc_load);
            dateTextView.setPadding(LocaleController.isRTL ? 0 : AndroidUtilities.dp(14), 0, LocaleController.isRTL ? AndroidUtilities.dp(14) : 0, 0);
            if (loading) {
                progressView.setVisibility(VISIBLE);
                Float progress = ImageLoader.getInstance().getFileProgress(fileName);
                if (progress == null) {
                    progress = 0.0f;
                }
                progressView.setProgress(progress, false);
            } else {
                progressView.setVisibility(INVISIBLE);
            }
        }
    } else {
        loading = false;
        loaded = true;
        progressView.setVisibility(INVISIBLE);
        progressView.setProgress(0, false);
        statusImageView.setVisibility(INVISIBLE);
        dateTextView.setPadding(0, 0, 0, 0);
        DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
    }
}
 
Example 7
Source File: OtherDocumentPlaceholderDrawable.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void checkFileExist() {
    if (parentMessageObject != null && parentMessageObject.messageOwner.media != null) {
        String fileName = null;
        File cacheFile;
        if (TextUtils.isEmpty(parentMessageObject.messageOwner.attachPath) || !(new File(parentMessageObject.messageOwner.attachPath).exists())) {
            cacheFile = FileLoader.getPathToMessage(parentMessageObject.messageOwner);
            if (!cacheFile.exists()) {
                fileName = FileLoader.getAttachFileName(parentMessageObject.getDocument());
            }
        }
        loaded = false;
        if (fileName == null) {
            progressVisible = false;
            loading = false;
            loaded = true;
            DownloadController.getInstance(parentMessageObject.currentAccount).removeLoadingFileObserver(this);
        } else {
            DownloadController.getInstance(parentMessageObject.currentAccount).addLoadingFileObserver(fileName, this);
            loading = FileLoader.getInstance(parentMessageObject.currentAccount).isLoadingFile(fileName);
            if (loading) {
                progressVisible = true;
                Float progress = ImageLoader.getInstance().getFileProgress(fileName);
                if (progress == null) {
                    progress = 0.0f;
                }
                setProgress(progress, false);
            } else {
                progressVisible = false;
            }
        }
    } else {
        loading = false;
        loaded = true;
        progressVisible = false;
        setProgress(0, false);
        DownloadController.getInstance(parentMessageObject.currentAccount).removeLoadingFileObserver(this);
    }
    parentView.invalidate();
}
 
Example 8
Source File: ThemesHorizontalListCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    Theme.ThemeInfo t = currentType == ThemeActivity.THEME_TYPE_NIGHT ? Theme.getCurrentNightTheme() : Theme.getCurrentTheme();
    button.setChecked(themeInfo == t, false);
    if (themeInfo != null && themeInfo.info != null && !themeInfo.themeLoaded) {
        String name = FileLoader.getAttachFileName(themeInfo.info.document);
        if (!loadingThemes.containsKey(name) && !loadingWallpapers.containsKey(themeInfo)) {
            themeInfo.themeLoaded = true;
            placeholderAlpha = 0.0f;
            parseTheme();
            applyTheme();
        }
    }
}
 
Example 9
Source File: ThemesHorizontalListCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setTheme(Theme.ThemeInfo theme, boolean last, boolean first) {
    themeInfo = theme;
    isFirst = first;
    isLast = last;
    accentId = theme.currentAccentId;
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) button.getLayoutParams();
    layoutParams.leftMargin = AndroidUtilities.dp(isFirst ? 22 + 27 : 27);
    button.setLayoutParams(layoutParams);
    placeholderAlpha = 0.0f;

    if (themeInfo.pathToFile != null && !themeInfo.previewParsed) {
        themeInfo.setPreviewInColor(Theme.getDefaultColor(Theme.key_chat_inBubble));
        themeInfo.setPreviewOutColor(Theme.getDefaultColor(Theme.key_chat_outBubble));
        File file = new File(themeInfo.pathToFile);
        boolean fileExists = file.exists();
        boolean parsed = fileExists && parseTheme();
        if ((!parsed || !fileExists) && themeInfo.info != null) {
            if (themeInfo.info.document != null) {
                themeInfo.themeLoaded = false;
                placeholderAlpha = 1.0f;
                loadingDrawable = getResources().getDrawable(R.drawable.msg_theme).mutate();
                Theme.setDrawableColor(loadingDrawable, loadingColor = Theme.getColor(Theme.key_windowBackgroundWhiteGrayText7));
                if (!fileExists) {
                    String name = FileLoader.getAttachFileName(themeInfo.info.document);
                    if (!loadingThemes.containsKey(name)) {
                        loadingThemes.put(name, themeInfo);
                        FileLoader.getInstance(themeInfo.account).loadFile(themeInfo.info.document, themeInfo.info, 1, 1);
                    }
                }
            } else {
                loadingDrawable = getResources().getDrawable(R.drawable.preview_custom).mutate();
                Theme.setDrawableColor(loadingDrawable, loadingColor = Theme.getColor(Theme.key_windowBackgroundWhiteGrayText7));
            }
        }
    }
    applyTheme();
}
 
Example 10
Source File: SharedDocumentCell.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void updateFileExistIcon() {
    if (message != null && message.messageOwner.media != null) {
        loaded = false;
        if (message.attachPathExists || message.mediaExists) {
            statusImageView.setVisibility(INVISIBLE);
            progressView.setVisibility(INVISIBLE);
            dateTextView.setPadding(0, 0, 0, 0);
            loading = false;
            loaded = true;
            DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
        } else {
            String fileName = FileLoader.getAttachFileName(message.getDocument());
            DownloadController.getInstance(currentAccount).addLoadingFileObserver(fileName, message, this);
            loading = FileLoader.getInstance(currentAccount).isLoadingFile(fileName);
            statusImageView.setVisibility(VISIBLE);
            statusImageView.setImageResource(loading ? R.drawable.media_doc_pause : R.drawable.media_doc_load);
            dateTextView.setPadding(LocaleController.isRTL ? 0 : AndroidUtilities.dp(14), 0, LocaleController.isRTL ? AndroidUtilities.dp(14) : 0, 0);
            if (loading) {
                progressView.setVisibility(VISIBLE);
                Float progress = ImageLoader.getInstance().getFileProgress(fileName);
                if (progress == null) {
                    progress = 0.0f;
                }
                progressView.setProgress(progress, false);
            } else {
                progressView.setVisibility(INVISIBLE);
            }
        }
    } else {
        loading = false;
        loaded = true;
        progressView.setVisibility(INVISIBLE);
        progressView.setProgress(0, false);
        statusImageView.setVisibility(INVISIBLE);
        dateTextView.setPadding(0, 0, 0, 0);
        DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
    }
}
 
Example 11
Source File: BlockingUpdateView.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void show(int account, TLRPC.TL_help_appUpdate update, boolean check) {
    pressCount = 0;
    appUpdate = update;
    accountNum = account;
    if (update.document instanceof TLRPC.TL_document) {
        fileName = FileLoader.getAttachFileName(update.document);
    }
    if (getVisibility() != VISIBLE) {
        setVisibility(VISIBLE);
    }
    SpannableStringBuilder builder = new SpannableStringBuilder(update.text);
    MessageObject.addEntitiesToText(builder, update.entities, false, false, false, false);
    textView.setText(builder);
    if (update.document instanceof TLRPC.TL_document) {
        acceptTextView.setText(LocaleController.getString("Update", R.string.Update) + String.format(Locale.US, " (%1$s)", AndroidUtilities.formatFileSize(update.document.size)));
    } else {
        acceptTextView.setText(LocaleController.getString("Update", R.string.Update));
    }
    NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.fileDidLoad);
    NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.fileDidFailToLoad);
    NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileLoadProgressChanged);
    if (check) {
        TLRPC.TL_help_getAppUpdate req = new TLRPC.TL_help_getAppUpdate();
        try {
            req.source = ApplicationLoader.applicationContext.getPackageManager().getInstallerPackageName(ApplicationLoader.applicationContext.getPackageName());
        } catch (Exception ignore) {

        }
        if (req.source == null) {
            req.source = "";
        }
        ConnectionsManager.getInstance(accountNum).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
            if (response instanceof TLRPC.TL_help_appUpdate) {
                final TLRPC.TL_help_appUpdate res = (TLRPC.TL_help_appUpdate) response;
                if (!res.can_not_skip) {
                    setVisibility(GONE);
                    UserConfig.getInstance(0).pendingAppUpdate = null;
                    UserConfig.getInstance(0).saveConfig(false);
                }
            }
        }));
    }
}
 
Example 12
Source File: UpdateAppAlertDialog.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public UpdateAppAlertDialog(final Activity activity, TLRPC.TL_help_appUpdate update, int account) {
    super(activity, 0);
    appUpdate = update;
    accountNum = account;
    if (update.document instanceof TLRPC.TL_document) {
        fileName = FileLoader.getAttachFileName(update.document);
    }
    parentActivity = activity;

    setTopImage(R.drawable.update, Theme.getColor(Theme.key_dialogTopBackground));
    setTopHeight(175);
    setMessage(appUpdate.text);
    if (appUpdate.document instanceof TLRPC.TL_document) {
        setSecondTitle(AndroidUtilities.formatFileSize(appUpdate.document.size));
    }
    setDismissDialogByButtons(false);
    setTitle(LocaleController.getString("UpdateTelegram", R.string.UpdateTelegram));
    setPositiveButton(LocaleController.getString("UpdateNow", R.string.UpdateNow), (dialog, which) -> {
        if (!BlockingUpdateView.checkApkInstallPermissions(getContext())) {
            return;
        }
        if (appUpdate.document instanceof TLRPC.TL_document) {
            if (!BlockingUpdateView.openApkInstall(parentActivity, appUpdate.document)) {
                FileLoader.getInstance(accountNum).loadFile(appUpdate.document, "update", 1, 1);
                showProgress(true);
            }
        } else if (appUpdate.url != null) {
            Browser.openUrl(getContext(), appUpdate.url);
            dialog.dismiss();
        }
    });
    setNeutralButton(LocaleController.getString("Later", R.string.Later), (dialog, which) -> {
        if (appUpdate.document instanceof TLRPC.TL_document) {
            FileLoader.getInstance(accountNum).cancelLoadFile(appUpdate.document);
        }
        dialog.dismiss();
    });

    radialProgressView = new FrameLayout(parentActivity) {
        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            int width = right - left;
            int height = bottom - top;
            int w = AndroidUtilities.dp(24);
            int l = (width - w) / 2;
            int t = (height - w) / 2 + AndroidUtilities.dp(2);
            radialProgress.setProgressRect(l, t, l + w, t + w);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            radialProgress.draw(canvas);
        }
    };
    radialProgressView.setWillNotDraw(false);
    radialProgressView.setAlpha(0.0f);
    radialProgressView.setScaleX(0.1f);
    radialProgressView.setScaleY(0.1f);
    radialProgressView.setVisibility(View.INVISIBLE);
    radialProgress = new RadialProgress(radialProgressView);
    radialProgress.setStrokeWidth(AndroidUtilities.dp(2));
    radialProgress.setBackground(null, true, false);
    radialProgress.setProgressColor(Theme.getColor(Theme.key_dialogButton));
}
 
Example 13
Source File: UpdateAppAlertDialog.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public UpdateAppAlertDialog(final Activity activity, TLRPC.TL_help_appUpdate update, int account) {
    super(activity, 0);
    appUpdate = update;
    accountNum = account;
    if (update.document instanceof TLRPC.TL_document) {
        fileName = FileLoader.getAttachFileName(update.document);
    }
    parentActivity = activity;

    setTopImage(R.drawable.update, Theme.getColor(Theme.key_dialogTopBackground));
    setTopHeight(175);
    setMessage(appUpdate.text);
    if (appUpdate.document instanceof TLRPC.TL_document) {
        setSecondTitle(AndroidUtilities.formatFileSize(appUpdate.document.size));
    }
    setDismissDialogByButtons(false);
    setTitle(LocaleController.getString("UpdateTelegram", R.string.UpdateTelegram));
    setPositiveButton(LocaleController.getString("UpdateNow", R.string.UpdateNow), (dialog, which) ->
    {
        if (!BlockingUpdateView.checkApkInstallPermissions(getContext())) {
            return;
        }
        if (appUpdate.document instanceof TLRPC.TL_document) {
            if (!BlockingUpdateView.openApkInstall(parentActivity, appUpdate.document)) {
                FileLoader.getInstance(accountNum).loadFile(appUpdate.document, true, 1);
                showProgress(true);
            }
        } else if (appUpdate.url != null) {
            Browser.openUrl(getContext(), appUpdate.url);
            dialog.dismiss();
        }
    });
    setNeutralButton(LocaleController.getString("Later", R.string.Later), (dialog, which) ->
    {
        if (appUpdate.document instanceof TLRPC.TL_document) {
            FileLoader.getInstance(accountNum).cancelLoadFile(appUpdate.document);
        }
        dialog.dismiss();
    });

    radialProgressView = new FrameLayout(parentActivity) {
        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            int width = right - left;
            int height = bottom - top;
            int w = AndroidUtilities.dp(24);
            int l = (width - w) / 2;
            int t = (height - w) / 2 + AndroidUtilities.dp(2);
            radialProgress.setProgressRect(l, t, l + w, t + w);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            radialProgress.draw(canvas);
        }
    };
    radialProgressView.setWillNotDraw(false);
    radialProgressView.setAlpha(0.0f);
    radialProgressView.setScaleX(0.1f);
    radialProgressView.setScaleY(0.1f);
    radialProgressView.setVisibility(View.INVISIBLE);
    radialProgress = new RadialProgress(radialProgressView);
    radialProgress.setStrokeWidth(AndroidUtilities.dp(2));
    radialProgress.setBackground(null, true, false);
    radialProgress.setProgressColor(Theme.getColor(Theme.key_dialogButton));
}
 
Example 14
Source File: SharedDocumentCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void updateFileExistIcon() {
    if (message != null && message.messageOwner.media != null) {
        String fileName = null;
        File cacheFile;
        if (message.messageOwner.attachPath == null || message.messageOwner.attachPath.length() == 0 || !(new File(message.messageOwner.attachPath).exists())) {
            cacheFile = FileLoader.getPathToMessage(message.messageOwner);
            if (!cacheFile.exists()) {
                fileName = FileLoader.getAttachFileName(message.getDocument());
            }
        }
        loaded = false;
        if (fileName == null) {
            statusImageView.setVisibility(INVISIBLE);
            progressView.setVisibility(INVISIBLE);
            dateTextView.setPadding(0, 0, 0, 0);
            loading = false;
            loaded = true;
            DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
        } else {
            DownloadController.getInstance(currentAccount).addLoadingFileObserver(fileName, this);
            loading = FileLoader.getInstance(currentAccount).isLoadingFile(fileName);
            statusImageView.setVisibility(VISIBLE);
            statusImageView.setImageResource(loading ? R.drawable.media_doc_pause : R.drawable.media_doc_load);
            dateTextView.setPadding(LocaleController.isRTL ? 0 : AndroidUtilities.dp(14), 0, LocaleController.isRTL ? AndroidUtilities.dp(14) : 0, 0);
            if (loading) {
                progressView.setVisibility(VISIBLE);
                Float progress = ImageLoader.getInstance().getFileProgress(fileName);
                if (progress == null) {
                    progress = 0.0f;
                }
                progressView.setProgress(progress, false);
            } else {
                progressView.setVisibility(INVISIBLE);
            }
        }
    } else {
        loading = false;
        loaded = true;
        progressView.setVisibility(INVISIBLE);
        progressView.setProgress(0, false);
        statusImageView.setVisibility(INVISIBLE);
        dateTextView.setPadding(0, 0, 0, 0);
        DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
    }
}
 
Example 15
Source File: UpdateAppAlertDialog.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public UpdateAppAlertDialog(final Activity activity, TLRPC.TL_help_appUpdate update, int account) {
    super(activity, 0);
    appUpdate = update;
    accountNum = account;
    if (update.document instanceof TLRPC.TL_document) {
        fileName = FileLoader.getAttachFileName(update.document);
    }
    parentActivity = activity;

    setTopImage(R.drawable.update, Theme.getColor(Theme.key_dialogTopBackground));
    setTopHeight(175);
    setMessage(appUpdate.text);
    if (appUpdate.document instanceof TLRPC.TL_document) {
        setSecondTitle(AndroidUtilities.formatFileSize(appUpdate.document.size));
    }
    setDismissDialogByButtons(false);
    setTitle(LocaleController.getString("UpdateTelegram", R.string.UpdateTelegram));
    setPositiveButton(LocaleController.getString("UpdateNow", R.string.UpdateNow), (dialog, which) ->
    {
        if (!BlockingUpdateView.checkApkInstallPermissions(getContext())) {
            return;
        }
        if (appUpdate.document instanceof TLRPC.TL_document) {
            if (!BlockingUpdateView.openApkInstall(parentActivity, appUpdate.document)) {
                FileLoader.getInstance(accountNum).loadFile(appUpdate.document, true, 1);
                showProgress(true);
            }
        } else if (appUpdate.url != null) {
            Browser.openUrl(getContext(), appUpdate.url);
            dialog.dismiss();
        }
    });
    setNeutralButton(LocaleController.getString("Later", R.string.Later), (dialog, which) ->
    {
        if (appUpdate.document instanceof TLRPC.TL_document) {
            FileLoader.getInstance(accountNum).cancelLoadFile(appUpdate.document);
        }
        dialog.dismiss();
    });

    radialProgressView = new FrameLayout(parentActivity) {
        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            int width = right - left;
            int height = bottom - top;
            int w = AndroidUtilities.dp(24);
            int l = (width - w) / 2;
            int t = (height - w) / 2 + AndroidUtilities.dp(2);
            radialProgress.setProgressRect(l, t, l + w, t + w);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            radialProgress.draw(canvas);
        }
    };
    radialProgressView.setWillNotDraw(false);
    radialProgressView.setAlpha(0.0f);
    radialProgressView.setScaleX(0.1f);
    radialProgressView.setScaleY(0.1f);
    radialProgressView.setVisibility(View.INVISIBLE);
    radialProgress = new RadialProgress(radialProgressView);
    radialProgress.setStrokeWidth(AndroidUtilities.dp(2));
    radialProgress.setBackground(null, true, false);
    radialProgress.setProgressColor(Theme.getColor(Theme.key_dialogButton));
}
 
Example 16
Source File: BlockingUpdateView.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void show(int account, TLRPC.TL_help_appUpdate update, boolean check) {
    pressCount = 0;
    appUpdate = update;
    accountNum = account;
    if (update.document instanceof TLRPC.TL_document) {
        fileName = FileLoader.getAttachFileName(update.document);
    }
    if (getVisibility() != VISIBLE) {
        setVisibility(VISIBLE);
    }
    SpannableStringBuilder builder = new SpannableStringBuilder(update.text);
    MessageObject.addEntitiesToText(builder, update.entities, false, false, false, false);
    textView.setText(builder);
    if (update.document instanceof TLRPC.TL_document) {
        acceptTextView.setText(LocaleController.getString("Update", R.string.Update) + String.format(Locale.US, " (%1$s)", AndroidUtilities.formatFileSize(update.document.size)));
    } else {
        acceptTextView.setText(LocaleController.getString("Update", R.string.Update));
    }
    NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.fileDidLoad);
    NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.fileDidFailToLoad);
    NotificationCenter.getInstance(accountNum).addObserver(this, NotificationCenter.FileLoadProgressChanged);
    if (check) {
        TLRPC.TL_help_getAppUpdate req = new TLRPC.TL_help_getAppUpdate();
        try {
            req.source = ApplicationLoader.applicationContext.getPackageManager().getInstallerPackageName(ApplicationLoader.applicationContext.getPackageName());
        } catch (Exception ignore) {

        }
        if (req.source == null) {
            req.source = "";
        }
        ConnectionsManager.getInstance(accountNum).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
            if (response instanceof TLRPC.TL_help_appUpdate) {
                final TLRPC.TL_help_appUpdate res = (TLRPC.TL_help_appUpdate) response;
                if (!res.can_not_skip) {
                    setVisibility(GONE);
                    UserConfig.getInstance(0).pendingAppUpdate = null;
                    UserConfig.getInstance(0).saveConfig(false);
                }
            }
        }));
    }
}
 
Example 17
Source File: UpdateAppAlertDialog.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public UpdateAppAlertDialog(final Activity activity, TLRPC.TL_help_appUpdate update, int account) {
    super(activity, 0);
    appUpdate = update;
    accountNum = account;
    if (update.document instanceof TLRPC.TL_document) {
        fileName = FileLoader.getAttachFileName(update.document);
    }
    parentActivity = activity;

    setTopImage(R.drawable.update, Theme.getColor(Theme.key_dialogTopBackground));
    setTopHeight(175);
    setMessage(appUpdate.text);
    if (appUpdate.document instanceof TLRPC.TL_document) {
        setSecondTitle(AndroidUtilities.formatFileSize(appUpdate.document.size));
    }
    setDismissDialogByButtons(false);
    setTitle(LocaleController.getString("UpdateTelegram", R.string.UpdateTelegram));
    setPositiveButton(LocaleController.getString("UpdateNow", R.string.UpdateNow), (dialog, which) -> {
        if (!BlockingUpdateView.checkApkInstallPermissions(getContext())) {
            return;
        }
        if (appUpdate.document instanceof TLRPC.TL_document) {
            if (!BlockingUpdateView.openApkInstall(parentActivity, appUpdate.document)) {
                FileLoader.getInstance(accountNum).loadFile(appUpdate.document, "update", 1, 1);
                showProgress(true);
            }
        } else if (appUpdate.url != null) {
            Browser.openUrl(getContext(), appUpdate.url);
            dialog.dismiss();
        }
    });
    setNeutralButton(LocaleController.getString("Later", R.string.Later), (dialog, which) -> {
        if (appUpdate.document instanceof TLRPC.TL_document) {
            FileLoader.getInstance(accountNum).cancelLoadFile(appUpdate.document);
        }
        dialog.dismiss();
    });

    radialProgressView = new FrameLayout(parentActivity) {
        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            int width = right - left;
            int height = bottom - top;
            int w = AndroidUtilities.dp(24);
            int l = (width - w) / 2;
            int t = (height - w) / 2 + AndroidUtilities.dp(2);
            radialProgress.setProgressRect(l, t, l + w, t + w);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            radialProgress.draw(canvas);
        }
    };
    radialProgressView.setWillNotDraw(false);
    radialProgressView.setAlpha(0.0f);
    radialProgressView.setScaleX(0.1f);
    radialProgressView.setScaleY(0.1f);
    radialProgressView.setVisibility(View.INVISIBLE);
    radialProgress = new RadialProgress(radialProgressView);
    radialProgress.setStrokeWidth(AndroidUtilities.dp(2));
    radialProgress.setBackground(null, true, false);
    radialProgress.setProgressColor(Theme.getColor(Theme.key_dialogButton));
}
 
Example 18
Source File: SharedDocumentCell.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void updateFileExistIcon() {
    if (message != null && message.messageOwner.media != null) {
        String fileName = null;
        File cacheFile;
        if (message.messageOwner.attachPath == null || message.messageOwner.attachPath.length() == 0 || !(new File(message.messageOwner.attachPath).exists())) {
            cacheFile = FileLoader.getPathToMessage(message.messageOwner);
            if (!cacheFile.exists()) {
                fileName = FileLoader.getAttachFileName(message.getDocument());
            }
        }
        loaded = false;
        if (fileName == null) {
            statusImageView.setVisibility(INVISIBLE);
            progressView.setVisibility(INVISIBLE);
            dateTextView.setPadding(0, 0, 0, 0);
            loading = false;
            loaded = true;
            DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
        } else {
            DownloadController.getInstance(currentAccount).addLoadingFileObserver(fileName, this);
            loading = FileLoader.getInstance(currentAccount).isLoadingFile(fileName);
            statusImageView.setVisibility(VISIBLE);
            statusImageView.setImageResource(loading ? R.drawable.media_doc_pause : R.drawable.media_doc_load);
            dateTextView.setPadding(LocaleController.isRTL ? 0 : AndroidUtilities.dp(14), 0, LocaleController.isRTL ? AndroidUtilities.dp(14) : 0, 0);
            if (loading) {
                progressView.setVisibility(VISIBLE);
                Float progress = ImageLoader.getInstance().getFileProgress(fileName);
                if (progress == null) {
                    progress = 0.0f;
                }
                progressView.setProgress(progress, false);
            } else {
                progressView.setVisibility(INVISIBLE);
            }
        }
    } else {
        loading = false;
        loaded = true;
        progressView.setVisibility(INVISIBLE);
        progressView.setProgress(0, false);
        statusImageView.setVisibility(INVISIBLE);
        dateTextView.setPadding(0, 0, 0, 0);
        DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
    }
}