Search in sources :

Example 1 with EmojiThemes

use of org.telegram.ui.ActionBar.EmojiThemes in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatThemeBottomSheet method applySelectedTheme.

private void applySelectedTheme() {
    Bulletin bulletin = null;
    EmojiThemes newTheme = selectedItem.chatTheme;
    if (newTheme.showAsDefaultStub) {
        newTheme = null;
    }
    if (selectedItem != null && newTheme != originalTheme) {
        EmojiThemes chatTheme = selectedItem.chatTheme;
        String emoticon = (chatTheme != null && !chatTheme.showAsDefaultStub) ? chatTheme.getEmoticon() : null;
        ChatThemeController.getInstance(currentAccount).setDialogTheme(chatActivity.getDialogId(), emoticon, true);
        if (chatTheme != null && !chatTheme.showAsDefaultStub) {
            themeDelegate.setCurrentTheme(chatTheme, true, originalIsDark);
        } else {
            themeDelegate.setCurrentTheme(null, true, originalIsDark);
        }
        isApplyClicked = true;
        TLRPC.User user = chatActivity.getCurrentUser();
        if (user != null && !user.self) {
            boolean themeDisabled = false;
            if (TextUtils.isEmpty(emoticon)) {
                themeDisabled = true;
                emoticon = "❌";
            }
            TLRPC.Document document = emoticon != null ? MediaDataController.getInstance(currentAccount).getEmojiAnimatedSticker(emoticon) : null;
            StickerSetBulletinLayout layout = new StickerSetBulletinLayout(getContext(), null, StickerSetBulletinLayout.TYPE_EMPTY, document, chatActivity.getResourceProvider());
            layout.subtitleTextView.setVisibility(View.GONE);
            if (themeDisabled) {
                layout.titleTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("ThemeAlsoDisabledForHint", R.string.ThemeAlsoDisabledForHint, user.first_name)));
            } else {
                layout.titleTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("ThemeAlsoAppliedForHint", R.string.ThemeAlsoAppliedForHint, user.first_name)));
            }
            layout.titleTextView.setTypeface(null);
            bulletin = Bulletin.make(chatActivity, layout, Bulletin.DURATION_LONG);
        }
    }
    dismiss();
    if (bulletin != null) {
        bulletin.show();
    }
}
Also used : EmojiThemes(org.telegram.ui.ActionBar.EmojiThemes) TLRPC(org.telegram.tgnet.TLRPC)

Example 2 with EmojiThemes

use of org.telegram.ui.ActionBar.EmojiThemes in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatThemeBottomSheet method onDataLoaded.

private void onDataLoaded(List<EmojiThemes> result) {
    if (result == null || result.isEmpty()) {
        return;
    }
    ChatThemeItem noThemeItem = new ChatThemeItem(result.get(0));
    List<ChatThemeItem> items = new ArrayList<>(result.size());
    EmojiThemes currentTheme = themeDelegate.getCurrentTheme();
    items.add(0, noThemeItem);
    selectedItem = noThemeItem;
    for (int i = 1; i < result.size(); ++i) {
        EmojiThemes chatTheme = result.get(i);
        ChatThemeItem item = new ChatThemeItem(chatTheme);
        chatTheme.loadPreviewColors(currentAccount);
        item.themeIndex = forceDark ? 1 : 0;
        items.add(item);
    }
    adapter.setItems(items);
    applyButton.setEnabled(true);
    applyTextView.setAlpha(0f);
    resetTextView.setAlpha(0f);
    recyclerView.setAlpha(0f);
    applyTextView.setVisibility(View.VISIBLE);
    resetTextView.setVisibility(View.VISIBLE);
    darkThemeView.setVisibility(View.VISIBLE);
    boolean showRestText = false;
    if (currentTheme != null) {
        int selectedPosition = -1;
        for (int i = 0; i != items.size(); ++i) {
            if (items.get(i).chatTheme.getEmoticon().equals(currentTheme.getEmoticon())) {
                selectedItem = items.get(i);
                selectedPosition = i;
                break;
            }
        }
        if (selectedPosition != -1) {
            prevSelectedPosition = selectedPosition;
            adapter.setSelectedItem(selectedPosition);
            if (selectedPosition > 0 && selectedPosition < items.size() / 2) {
                selectedPosition -= 1;
            }
            int finalSelectedPosition = Math.min(selectedPosition, adapter.items.size() - 1);
            layoutManager.scrollToPositionWithOffset(finalSelectedPosition, 0);
        }
    } else {
        showRestText = true;
        adapter.setSelectedItem(0);
        layoutManager.scrollToPositionWithOffset(0, 0);
    }
    recyclerView.animate().alpha(1f).setDuration(150).start();
    resetTextView.animate().alpha(showRestText ? 1f : 0).setDuration(150).start();
    applyTextView.animate().alpha(showRestText ? 0f : 1).setDuration(150).start();
    progressView.animate().alpha(0f).setListener(new HideViewAfterAnimation(progressView)).setDuration(150).start();
}
Also used : EmojiThemes(org.telegram.ui.ActionBar.EmojiThemes) ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 3 with EmojiThemes

use of org.telegram.ui.ActionBar.EmojiThemes in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatThemeController method getDialogTheme.

public EmojiThemes getDialogTheme(long dialogId) {
    String emoticon = dialogEmoticonsMap.get(dialogId);
    if (emoticon == null) {
        emoticon = getEmojiSharedPreferences().getString("chatTheme_" + currentAccount + "_" + dialogId, null);
        dialogEmoticonsMap.put(dialogId, emoticon);
    }
    if (emoticon != null) {
        for (EmojiThemes theme : allChatThemes) {
            if (emoticon.equals(theme.getEmoticon())) {
                return theme;
            }
        }
    }
    return null;
}
Also used : EmojiThemes(org.telegram.ui.ActionBar.EmojiThemes)

Example 4 with EmojiThemes

use of org.telegram.ui.ActionBar.EmojiThemes in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatThemeController method preloadAllWallpaperThumbs.

public static void preloadAllWallpaperThumbs(boolean isDark) {
    for (EmojiThemes chatTheme : allChatThemes) {
        TLRPC.TL_theme theme = chatTheme.getTlTheme(isDark ? 1 : 0);
        if (theme == null) {
            continue;
        }
        long themeId = theme.id;
        if (themeIdWallpaperThumbMap.containsKey(themeId)) {
            continue;
        }
        chatTheme.loadWallpaperThumb(isDark ? 1 : 0, result -> {
            if (result != null) {
                themeIdWallpaperThumbMap.put(result.first, result.second);
            }
        });
    }
}
Also used : EmojiThemes(org.telegram.ui.ActionBar.EmojiThemes) TLRPC(org.telegram.tgnet.TLRPC)

Example 5 with EmojiThemes

use of org.telegram.ui.ActionBar.EmojiThemes in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatThemeController method init.

public static void init() {
    SharedPreferences preferences = getSharedPreferences();
    themesHash = 0;
    lastReloadTimeMs = 0;
    try {
        themesHash = preferences.getLong("hash", 0);
        lastReloadTimeMs = preferences.getLong("lastReload", 0);
    } catch (Exception e) {
        FileLog.e(e);
    }
    allChatThemes = getAllChatThemesFromPrefs();
    preloadSticker("❌");
    if (!allChatThemes.isEmpty()) {
        for (EmojiThemes chatTheme : allChatThemes) {
            preloadSticker(chatTheme.getEmoticon());
        }
    }
}
Also used : EmojiThemes(org.telegram.ui.ActionBar.EmojiThemes) SharedPreferences(android.content.SharedPreferences)

Aggregations

EmojiThemes (org.telegram.ui.ActionBar.EmojiThemes)11 TLRPC (org.telegram.tgnet.TLRPC)7 ArrayList (java.util.ArrayList)5 SuppressLint (android.annotation.SuppressLint)4 Paint (android.graphics.Paint)4 TextPaint (android.text.TextPaint)3 SharedPreferences (android.content.SharedPreferences)2 Bitmap (android.graphics.Bitmap)2 List (java.util.List)2 SerializedData (org.telegram.tgnet.SerializedData)2 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 ObjectAnimator (android.animation.ObjectAnimator)1 ValueAnimator (android.animation.ValueAnimator)1 Canvas (android.graphics.Canvas)1 PorterDuffXfermode (android.graphics.PorterDuffXfermode)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1