Search in sources :

Example 1 with ThemeTypeCell

use of org.telegram.ui.Cells.ThemeTypeCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class ThemeActivity method updateRows.

private void updateRows(boolean notify) {
    int oldRowCount = rowCount;
    int prevThemeAccentListRow = themeAccentListRow;
    int prevEditThemeRow = editThemeRow;
    rowCount = 0;
    emojiRow = -1;
    contactsReimportRow = -1;
    contactsSortRow = -1;
    scheduleLocationRow = -1;
    scheduleUpdateLocationRow = -1;
    scheduleLocationInfoRow = -1;
    nightDisabledRow = -1;
    nightScheduledRow = -1;
    nightAutomaticRow = -1;
    nightSystemDefaultRow = -1;
    nightTypeInfoRow = -1;
    scheduleHeaderRow = -1;
    nightThemeRow = -1;
    newThemeInfoRow = -1;
    scheduleFromRow = -1;
    scheduleToRow = -1;
    scheduleFromToInfoRow = -1;
    themeListRow = -1;
    themeListRow2 = -1;
    themeAccentListRow = -1;
    themeInfoRow = -1;
    preferedHeaderRow = -1;
    automaticHeaderRow = -1;
    automaticBrightnessRow = -1;
    automaticBrightnessInfoRow = -1;
    textSizeHeaderRow = -1;
    themeHeaderRow = -1;
    bubbleRadiusHeaderRow = -1;
    bubbleRadiusRow = -1;
    bubbleRadiusInfoRow = -1;
    chatListHeaderRow = -1;
    chatListRow = -1;
    chatListInfoRow = -1;
    reactionsDoubleTapRow = -1;
    chatBlurRow = -1;
    textSizeRow = -1;
    backgroundRow = -1;
    settingsRow = -1;
    customTabsRow = -1;
    directShareRow = -1;
    enableAnimationsRow = -1;
    raiseToSpeakRow = -1;
    sendByEnterRow = -1;
    saveToGalleryRow = -1;
    distanceRow = -1;
    settings2Row = -1;
    stickersRow = -1;
    stickersSection2Row = -1;
    swipeGestureHeaderRow = -1;
    swipeGestureRow = -1;
    swipeGestureInfoRow = -1;
    selectThemeHeaderRow = -1;
    themePreviewRow = -1;
    editThemeRow = -1;
    createNewThemeRow = -1;
    defaultThemes.clear();
    darkThemes.clear();
    for (int a = 0, N = Theme.themes.size(); a < N; a++) {
        Theme.ThemeInfo themeInfo = Theme.themes.get(a);
        if (currentType != THEME_TYPE_BASIC && currentType != THEME_TYPE_THEMES_BROWSER) {
            if (themeInfo.isLight() || themeInfo.info != null && themeInfo.info.document == null) {
                continue;
            }
        }
        if (themeInfo.pathToFile != null) {
            darkThemes.add(themeInfo);
        } else {
            defaultThemes.add(themeInfo);
        }
    }
    Collections.sort(defaultThemes, (o1, o2) -> Integer.compare(o1.sortIndex, o2.sortIndex));
    if (currentType == THEME_TYPE_THEMES_BROWSER) {
        selectThemeHeaderRow = rowCount++;
        themeListRow2 = rowCount++;
        chatListInfoRow = rowCount++;
        themePreviewRow = rowCount++;
        themeHeaderRow = rowCount++;
        themeListRow = rowCount++;
        hasThemeAccents = Theme.getCurrentTheme().hasAccentColors();
        if (themesHorizontalListCell != null) {
            themesHorizontalListCell.setDrawDivider(hasThemeAccents);
        }
        if (hasThemeAccents) {
            themeAccentListRow = rowCount++;
        }
        bubbleRadiusInfoRow = rowCount++;
        Theme.ThemeInfo themeInfo = Theme.getCurrentTheme();
        Theme.ThemeAccent accent = themeInfo.getAccent(false);
        if (themeInfo.themeAccents != null && !themeInfo.themeAccents.isEmpty() && accent != null && accent.id >= 100) {
            editThemeRow = rowCount++;
        }
        createNewThemeRow = rowCount++;
        swipeGestureInfoRow = rowCount++;
    } else if (currentType == THEME_TYPE_BASIC) {
        textSizeHeaderRow = rowCount++;
        textSizeRow = rowCount++;
        backgroundRow = rowCount++;
        newThemeInfoRow = rowCount++;
        themeHeaderRow = rowCount++;
        themeListRow2 = rowCount++;
        // 
        // themeListRow = rowCount++;
        // hasThemeAccents = Theme.getCurrentTheme().hasAccentColors();
        // if (themesHorizontalListCell != null) {
        // themesHorizontalListCell.setDrawDivider(hasThemeAccents);
        // }
        // if (hasThemeAccents) {
        // themeAccentListRow = rowCount++;
        // }
        // 
        themeInfoRow = rowCount++;
        bubbleRadiusHeaderRow = rowCount++;
        bubbleRadiusRow = rowCount++;
        bubbleRadiusInfoRow = rowCount++;
        chatListHeaderRow = rowCount++;
        chatListRow = rowCount++;
        chatListInfoRow = rowCount++;
        swipeGestureHeaderRow = rowCount++;
        swipeGestureRow = rowCount++;
        swipeGestureInfoRow = rowCount++;
        settingsRow = rowCount++;
        nightThemeRow = rowCount++;
        customTabsRow = rowCount++;
        directShareRow = rowCount++;
        enableAnimationsRow = rowCount++;
        emojiRow = rowCount++;
        raiseToSpeakRow = rowCount++;
        sendByEnterRow = rowCount++;
        saveToGalleryRow = rowCount++;
        if (SharedConfig.canBlurChat()) {
            chatBlurRow = rowCount++;
        }
        distanceRow = rowCount++;
        reactionsDoubleTapRow = rowCount++;
        settings2Row = rowCount++;
        stickersRow = rowCount++;
        stickersSection2Row = rowCount++;
    } else {
        nightDisabledRow = rowCount++;
        nightScheduledRow = rowCount++;
        nightAutomaticRow = rowCount++;
        if (Build.VERSION.SDK_INT >= 29) {
            nightSystemDefaultRow = rowCount++;
        }
        nightTypeInfoRow = rowCount++;
        if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_SCHEDULED) {
            scheduleHeaderRow = rowCount++;
            scheduleLocationRow = rowCount++;
            if (Theme.autoNightScheduleByLocation) {
                scheduleUpdateLocationRow = rowCount++;
                scheduleLocationInfoRow = rowCount++;
            } else {
                scheduleFromRow = rowCount++;
                scheduleToRow = rowCount++;
                scheduleFromToInfoRow = rowCount++;
            }
        } else if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_AUTOMATIC) {
            automaticHeaderRow = rowCount++;
            automaticBrightnessRow = rowCount++;
            automaticBrightnessInfoRow = rowCount++;
        }
        if (Theme.selectedAutoNightType != Theme.AUTO_NIGHT_TYPE_NONE) {
            preferedHeaderRow = rowCount++;
            themeListRow = rowCount++;
            hasThemeAccents = Theme.getCurrentNightTheme().hasAccentColors();
            if (themesHorizontalListCell != null) {
                themesHorizontalListCell.setDrawDivider(hasThemeAccents);
            }
            if (hasThemeAccents) {
                themeAccentListRow = rowCount++;
            }
            themeInfoRow = rowCount++;
        }
    }
    if (themesHorizontalListCell != null) {
        themesHorizontalListCell.notifyDataSetChanged(listView.getWidth());
    }
    if (listAdapter != null) {
        if (currentType != THEME_TYPE_NIGHT || previousUpdatedType == Theme.selectedAutoNightType || previousUpdatedType == -1) {
            if (notify || previousUpdatedType == -1) {
                listAdapter.notifyDataSetChanged();
            } else {
                if (prevThemeAccentListRow == -1 && themeAccentListRow != -1) {
                    listAdapter.notifyItemInserted(themeAccentListRow);
                } else if (prevThemeAccentListRow != -1 && themeAccentListRow == -1) {
                    listAdapter.notifyItemRemoved(prevThemeAccentListRow);
                    if (prevEditThemeRow != -1) {
                        prevEditThemeRow--;
                    }
                } else if (themeAccentListRow != -1) {
                    listAdapter.notifyItemChanged(themeAccentListRow);
                }
                if (prevEditThemeRow == -1 && editThemeRow != -1) {
                    listAdapter.notifyItemInserted(editThemeRow);
                } else if (prevEditThemeRow != -1 && editThemeRow == -1) {
                    listAdapter.notifyItemRemoved(prevEditThemeRow);
                }
            }
        } else {
            int start = nightTypeInfoRow + 1;
            if (previousUpdatedType != Theme.selectedAutoNightType) {
                for (int a = 0; a < 4; a++) {
                    RecyclerListView.Holder holder = (RecyclerListView.Holder) listView.findViewHolderForAdapterPosition(a);
                    if (holder == null || !(holder.itemView instanceof ThemeTypeCell)) {
                        continue;
                    }
                    ((ThemeTypeCell) holder.itemView).setTypeChecked(a == Theme.selectedAutoNightType);
                }
                if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_NONE) {
                    listAdapter.notifyItemRangeRemoved(start, oldRowCount - start);
                } else if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_SCHEDULED) {
                    if (previousUpdatedType == Theme.AUTO_NIGHT_TYPE_NONE) {
                        listAdapter.notifyItemRangeInserted(start, rowCount - start);
                    } else if (previousUpdatedType == Theme.AUTO_NIGHT_TYPE_AUTOMATIC) {
                        listAdapter.notifyItemRangeRemoved(start, 3);
                        listAdapter.notifyItemRangeInserted(start, Theme.autoNightScheduleByLocation ? 4 : 5);
                    } else if (previousUpdatedType == Theme.AUTO_NIGHT_TYPE_SYSTEM) {
                        listAdapter.notifyItemRangeInserted(start, Theme.autoNightScheduleByLocation ? 4 : 5);
                    }
                } else if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_AUTOMATIC) {
                    if (previousUpdatedType == Theme.AUTO_NIGHT_TYPE_NONE) {
                        listAdapter.notifyItemRangeInserted(start, rowCount - start);
                    } else if (previousUpdatedType == Theme.AUTO_NIGHT_TYPE_SCHEDULED) {
                        listAdapter.notifyItemRangeRemoved(start, Theme.autoNightScheduleByLocation ? 4 : 5);
                        listAdapter.notifyItemRangeInserted(start, 3);
                    } else if (previousUpdatedType == Theme.AUTO_NIGHT_TYPE_SYSTEM) {
                        listAdapter.notifyItemRangeInserted(start, 3);
                    }
                } else if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_SYSTEM) {
                    if (previousUpdatedType == Theme.AUTO_NIGHT_TYPE_NONE) {
                        listAdapter.notifyItemRangeInserted(start, rowCount - start);
                    } else if (previousUpdatedType == Theme.AUTO_NIGHT_TYPE_AUTOMATIC) {
                        listAdapter.notifyItemRangeRemoved(start, 3);
                    } else if (previousUpdatedType == Theme.AUTO_NIGHT_TYPE_SCHEDULED) {
                        listAdapter.notifyItemRangeRemoved(start, Theme.autoNightScheduleByLocation ? 4 : 5);
                    }
                }
            } else {
                if (previousByLocation != Theme.autoNightScheduleByLocation) {
                    listAdapter.notifyItemRangeRemoved(start + 2, Theme.autoNightScheduleByLocation ? 3 : 2);
                    listAdapter.notifyItemRangeInserted(start + 2, Theme.autoNightScheduleByLocation ? 2 : 3);
                }
            }
        }
    }
    if (currentType == THEME_TYPE_NIGHT) {
        previousByLocation = Theme.autoNightScheduleByLocation;
        previousUpdatedType = Theme.selectedAutoNightType;
    }
    updateMenuItem();
}
Also used : Theme(org.telegram.ui.ActionBar.Theme) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) ThemeTypeCell(org.telegram.ui.Cells.ThemeTypeCell)

Aggregations

Paint (android.graphics.Paint)1 TextPaint (android.text.TextPaint)1 Theme (org.telegram.ui.ActionBar.Theme)1 ThemeTypeCell (org.telegram.ui.Cells.ThemeTypeCell)1 RecyclerListView (org.telegram.ui.Components.RecyclerListView)1