Search in sources :

Example 1 with StorageDiagramView

use of org.telegram.ui.Components.StorageDiagramView in project Telegram-FOSS by Telegram-FOSS-Team.

the class CacheControlActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("StorageUsage", R.string.StorageUsage));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    listAdapter = new ListAdapter(context);
    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    listView = new RecyclerListView(context);
    listView.setVerticalScrollBarEnabled(false);
    listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener((view, position) -> {
        if (getParentActivity() == null) {
            return;
        }
        if (position == migrateOldFolderRow) {
            migrateOldFolder();
        } else if (position == databaseRow) {
            clearDatabase();
        } else if (position == storageUsageRow) {
            if (totalSize <= 0 || getParentActivity() == null) {
                return;
            }
            bottomSheet = new BottomSheet(getParentActivity(), false) {

                @Override
                protected boolean canDismissWithSwipe() {
                    return false;
                }
            };
            bottomSheet.setAllowNestedScroll(true);
            bottomSheet.setApplyBottomPadding(false);
            LinearLayout linearLayout = new LinearLayout(getParentActivity());
            bottomSheetView = linearLayout;
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            StorageDiagramView circleDiagramView = new StorageDiagramView(context);
            linearLayout.addView(circleDiagramView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL, 0, 16, 0, 16));
            CheckBoxCell lastCreatedCheckbox = null;
            for (int a = 0; a < 7; a++) {
                long size;
                String name;
                String color;
                if (a == 0) {
                    size = photoSize;
                    name = LocaleController.getString("LocalPhotoCache", R.string.LocalPhotoCache);
                    color = Theme.key_statisticChartLine_blue;
                } else if (a == 1) {
                    size = videoSize;
                    name = LocaleController.getString("LocalVideoCache", R.string.LocalVideoCache);
                    color = Theme.key_statisticChartLine_golden;
                } else if (a == 2) {
                    size = documentsSize;
                    name = LocaleController.getString("LocalDocumentCache", R.string.LocalDocumentCache);
                    color = Theme.key_statisticChartLine_green;
                } else if (a == 3) {
                    size = musicSize;
                    name = LocaleController.getString("LocalMusicCache", R.string.LocalMusicCache);
                    color = Theme.key_statisticChartLine_indigo;
                } else if (a == 4) {
                    size = audioSize;
                    name = LocaleController.getString("LocalAudioCache", R.string.LocalAudioCache);
                    color = Theme.key_statisticChartLine_red;
                } else if (a == 5) {
                    size = stickersSize;
                    name = LocaleController.getString("AnimatedStickers", R.string.AnimatedStickers);
                    color = Theme.key_statisticChartLine_lightgreen;
                } else {
                    size = cacheSize;
                    name = LocaleController.getString("LocalCache", R.string.LocalCache);
                    color = Theme.key_statisticChartLine_lightblue;
                }
                if (size > 0) {
                    clearViewData[a] = new StorageDiagramView.ClearViewData(circleDiagramView);
                    clearViewData[a].size = size;
                    clearViewData[a].color = color;
                    CheckBoxCell checkBoxCell = new CheckBoxCell(getParentActivity(), 4, 21, null);
                    lastCreatedCheckbox = checkBoxCell;
                    checkBoxCell.setTag(a);
                    checkBoxCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
                    linearLayout.addView(checkBoxCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
                    checkBoxCell.setText(name, AndroidUtilities.formatFileSize(size), true, true);
                    checkBoxCell.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
                    checkBoxCell.setCheckBoxColor(color, Theme.key_windowBackgroundWhiteGrayIcon, Theme.key_checkboxCheck);
                    checkBoxCell.setOnClickListener(v -> {
                        int enabledCount = 0;
                        for (int i = 0; i < clearViewData.length; i++) {
                            if (clearViewData[i] != null && clearViewData[i].clear) {
                                enabledCount++;
                            }
                        }
                        CheckBoxCell cell = (CheckBoxCell) v;
                        int num = (Integer) cell.getTag();
                        if (enabledCount == 1 && clearViewData[num].clear) {
                            AndroidUtilities.shakeView(((CheckBoxCell) v).getCheckBoxView(), 2, 0);
                            return;
                        }
                        clearViewData[num].setClear(!clearViewData[num].clear);
                        cell.setChecked(clearViewData[num].clear, true);
                    });
                } else {
                    clearViewData[a] = null;
                }
            }
            if (lastCreatedCheckbox != null) {
                lastCreatedCheckbox.setNeedDivider(false);
            }
            circleDiagramView.setData(clearViewData);
            BottomSheet.BottomSheetCell cell = new BottomSheet.BottomSheetCell(getParentActivity(), 2);
            cell.setTextAndIcon(LocaleController.getString("ClearMediaCache", R.string.ClearMediaCache), 0);
            actionTextView = cell.getTextView();
            cell.getTextView().setOnClickListener(v -> {
                try {
                    if (visibleDialog != null) {
                        visibleDialog.dismiss();
                    }
                } catch (Exception e) {
                    FileLog.e(e);
                }
                cleanupFolders();
            });
            linearLayout.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
            NestedScrollView scrollView = new NestedScrollView(context);
            scrollView.setVerticalScrollBarEnabled(false);
            scrollView.addView(linearLayout);
            bottomSheet.setCustomView(scrollView);
            showDialog(bottomSheet);
        }
    });
    cacheRemovedTooltip = new UndoView(context);
    frameLayout.addView(cacheRemovedTooltip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 8, 0, 8, 8));
    return fragmentView;
}
Also used : RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) TextCheckBoxCell(org.telegram.ui.Cells.TextCheckBoxCell) UndoView(org.telegram.ui.Components.UndoView) StorageDiagramView(org.telegram.ui.Components.StorageDiagramView) FrameLayout(android.widget.FrameLayout) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) NestedScrollView(androidx.core.widget.NestedScrollView) ActionBar(org.telegram.ui.ActionBar.ActionBar) LinearLayout(android.widget.LinearLayout)

Aggregations

FrameLayout (android.widget.FrameLayout)1 LinearLayout (android.widget.LinearLayout)1 NestedScrollView (androidx.core.widget.NestedScrollView)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 ActionBar (org.telegram.ui.ActionBar.ActionBar)1 BottomSheet (org.telegram.ui.ActionBar.BottomSheet)1 CheckBoxCell (org.telegram.ui.Cells.CheckBoxCell)1 TextCheckBoxCell (org.telegram.ui.Cells.TextCheckBoxCell)1 RecyclerListView (org.telegram.ui.Components.RecyclerListView)1 StorageDiagramView (org.telegram.ui.Components.StorageDiagramView)1 UndoView (org.telegram.ui.Components.UndoView)1