Search in sources :

Example 1 with BottomSheet

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

the class AlertsCreator method createReportAlert.

public static void createReportAlert(final Context context, final long dialog_id, final int messageId, final BaseFragment parentFragment, Theme.ResourcesProvider resourcesProvider, Runnable hideDim) {
    if (context == null || parentFragment == null) {
        return;
    }
    BottomSheet.Builder builder = new BottomSheet.Builder(context, true, resourcesProvider);
    builder.setDimBehind(hideDim == null);
    builder.setOnPreDismissListener(di -> {
        if (hideDim != null) {
            hideDim.run();
        }
    });
    builder.setTitle(LocaleController.getString("ReportChat", R.string.ReportChat), true);
    CharSequence[] items;
    int[] icons;
    if (messageId != 0) {
        items = new CharSequence[] { LocaleController.getString("ReportChatSpam", R.string.ReportChatSpam), LocaleController.getString("ReportChatViolence", R.string.ReportChatViolence), LocaleController.getString("ReportChatChild", R.string.ReportChatChild), LocaleController.getString("ReportChatPornography", R.string.ReportChatPornography), LocaleController.getString("ReportChatOther", R.string.ReportChatOther) };
        icons = new int[] { R.drawable.msg_report_spam, R.drawable.msg_report_violence, R.drawable.msg_report_abuse, R.drawable.msg_report_xxx, R.drawable.msg_report_other };
    } else {
        items = new CharSequence[] { LocaleController.getString("ReportChatSpam", R.string.ReportChatSpam), LocaleController.getString("ReportChatFakeAccount", R.string.ReportChatFakeAccount), LocaleController.getString("ReportChatViolence", R.string.ReportChatViolence), LocaleController.getString("ReportChatChild", R.string.ReportChatChild), LocaleController.getString("ReportChatPornography", R.string.ReportChatPornography), LocaleController.getString("ReportChatOther", R.string.ReportChatOther) };
        icons = new int[] { R.drawable.msg_report_spam, R.drawable.msg_report_fake, R.drawable.msg_report_violence, R.drawable.msg_report_abuse, R.drawable.msg_report_xxx, R.drawable.msg_report_other };
    }
    builder.setItems(items, icons, (dialogInterface, i) -> {
        if (messageId == 0 && (i == 0 || i == 2 || i == 3 || i == 4) && parentFragment instanceof ChatActivity) {
            ((ChatActivity) parentFragment).openReportChat(i);
            return;
        } else if (messageId == 0 && (i == 5 || i == 1) || messageId != 0 && i == 4) {
            if (parentFragment instanceof ChatActivity) {
                AndroidUtilities.requestAdjustNothing(parentFragment.getParentActivity(), parentFragment.getClassGuid());
            }
            parentFragment.showDialog(new ReportAlert(context, i == 4 ? 5 : i) {

                @Override
                public void dismissInternal() {
                    super.dismissInternal();
                    if (parentFragment instanceof ChatActivity) {
                        ((ChatActivity) parentFragment).checkAdjustResize();
                    }
                }

                @Override
                protected void onSend(int type, String message) {
                    ArrayList<Integer> ids = new ArrayList<>();
                    if (messageId != 0) {
                        ids.add(messageId);
                    }
                    TLRPC.InputPeer peer = MessagesController.getInstance(UserConfig.selectedAccount).getInputPeer(dialog_id);
                    sendReport(peer, type, message, ids);
                    if (parentFragment instanceof ChatActivity) {
                        ((ChatActivity) parentFragment).getUndoView().showWithAction(0, UndoView.ACTION_REPORT_SENT, null);
                    }
                }
            });
            return;
        }
        TLObject req;
        TLRPC.InputPeer peer = MessagesController.getInstance(UserConfig.selectedAccount).getInputPeer(dialog_id);
        if (messageId != 0) {
            TLRPC.TL_messages_report request = new TLRPC.TL_messages_report();
            request.peer = peer;
            request.id.add(messageId);
            request.message = "";
            if (i == 0) {
                request.reason = new TLRPC.TL_inputReportReasonSpam();
            } else if (i == 1) {
                request.reason = new TLRPC.TL_inputReportReasonViolence();
            } else if (i == 2) {
                request.reason = new TLRPC.TL_inputReportReasonChildAbuse();
            } else if (i == 3) {
                request.reason = new TLRPC.TL_inputReportReasonPornography();
            }
            req = request;
        } else {
            TLRPC.TL_account_reportPeer request = new TLRPC.TL_account_reportPeer();
            request.peer = peer;
            request.message = "";
            if (i == 0) {
                request.reason = new TLRPC.TL_inputReportReasonSpam();
            } else if (i == 1) {
                request.reason = new TLRPC.TL_inputReportReasonFake();
            } else if (i == 2) {
                request.reason = new TLRPC.TL_inputReportReasonViolence();
            } else if (i == 3) {
                request.reason = new TLRPC.TL_inputReportReasonChildAbuse();
            } else if (i == 4) {
                request.reason = new TLRPC.TL_inputReportReasonPornography();
            }
            req = request;
        }
        ConnectionsManager.getInstance(UserConfig.selectedAccount).sendRequest(req, (response, error) -> {
        });
        if (parentFragment instanceof ChatActivity) {
            ((ChatActivity) parentFragment).getUndoView().showWithAction(0, UndoView.ACTION_REPORT_SENT, null);
        } else {
            BulletinFactory.of(parentFragment).createReportSent(resourcesProvider).show();
        }
    });
    BottomSheet sheet = builder.create();
    parentFragment.showDialog(sheet);
}
Also used : ChatActivity(org.telegram.ui.ChatActivity) SpannableStringBuilder(android.text.SpannableStringBuilder) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) TLRPC(org.telegram.tgnet.TLRPC) TLObject(org.telegram.tgnet.TLObject) BottomSheet(org.telegram.ui.ActionBar.BottomSheet)

Example 2 with BottomSheet

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

the class AlertsCreator method createMuteAlert.

public static BottomSheet createMuteAlert(BaseFragment fragment, final long dialog_id, Theme.ResourcesProvider resourcesProvider) {
    if (fragment == null || fragment.getParentActivity() == null) {
        return null;
    }
    BottomSheet.Builder builder = new BottomSheet.Builder(fragment.getParentActivity(), false, resourcesProvider);
    builder.setTitle(LocaleController.getString("Notifications", R.string.Notifications), true);
    CharSequence[] items = new CharSequence[] { LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 1)), LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Hours", 8)), LocaleController.formatString("MuteFor", R.string.MuteFor, LocaleController.formatPluralString("Days", 2)), LocaleController.getString("MuteDisable", R.string.MuteDisable) };
    builder.setItems(items, (dialogInterface, i) -> {
        int setting;
        if (i == 0) {
            setting = NotificationsController.SETTING_MUTE_HOUR;
        } else if (i == 1) {
            setting = NotificationsController.SETTING_MUTE_8_HOURS;
        } else if (i == 2) {
            setting = NotificationsController.SETTING_MUTE_2_DAYS;
        } else {
            setting = NotificationsController.SETTING_MUTE_FOREVER;
        }
        NotificationsController.getInstance(UserConfig.selectedAccount).setDialogNotificationsSettings(dialog_id, setting);
        if (BulletinFactory.canShowBulletin(fragment)) {
            BulletinFactory.createMuteBulletin(fragment, setting, resourcesProvider).show();
        }
    });
    return builder.create();
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) SuppressLint(android.annotation.SuppressLint)

Example 3 with BottomSheet

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

the class ImageUpdater method openMenu.

public void openMenu(boolean hasAvatar, Runnable onDeleteAvatar, DialogInterface.OnDismissListener onDismiss) {
    if (parentFragment == null || parentFragment.getParentActivity() == null) {
        return;
    }
    if (useAttachMenu) {
        openAttachMenu(onDismiss);
        return;
    }
    BottomSheet.Builder builder = new BottomSheet.Builder(parentFragment.getParentActivity());
    builder.setTitle(LocaleController.getString("ChoosePhoto", R.string.ChoosePhoto), true);
    ArrayList<CharSequence> items = new ArrayList<>();
    ArrayList<Integer> icons = new ArrayList<>();
    ArrayList<Integer> ids = new ArrayList<>();
    items.add(LocaleController.getString("ChooseTakePhoto", R.string.ChooseTakePhoto));
    icons.add(R.drawable.menu_camera);
    ids.add(0);
    if (canSelectVideo) {
        items.add(LocaleController.getString("ChooseRecordVideo", R.string.ChooseRecordVideo));
        icons.add(R.drawable.msg_video);
        ids.add(4);
    }
    items.add(LocaleController.getString("ChooseFromGallery", R.string.ChooseFromGallery));
    icons.add(R.drawable.profile_photos);
    ids.add(1);
    if (searchAvailable) {
        items.add(LocaleController.getString("ChooseFromSearch", R.string.ChooseFromSearch));
        icons.add(R.drawable.menu_search);
        ids.add(2);
    }
    if (hasAvatar) {
        items.add(LocaleController.getString("DeletePhoto", R.string.DeletePhoto));
        icons.add(R.drawable.chats_delete);
        ids.add(3);
    }
    int[] iconsRes = new int[icons.size()];
    for (int i = 0, N = icons.size(); i < N; i++) {
        iconsRes[i] = icons.get(i);
    }
    builder.setItems(items.toArray(new CharSequence[0]), iconsRes, (dialogInterface, i) -> {
        int id = ids.get(i);
        if (id == 0) {
            openCamera();
        } else if (id == 1) {
            openGallery();
        } else if (id == 2) {
            openSearch();
        } else if (id == 3) {
            onDeleteAvatar.run();
        } else if (id == 4) {
            openVideoCamera();
        }
    });
    BottomSheet sheet = builder.create();
    sheet.setOnHideListener(onDismiss);
    parentFragment.showDialog(sheet);
    if (hasAvatar) {
        sheet.setItemColor(items.size() - 1, Theme.getColor(Theme.key_dialogTextRed2), Theme.getColor(Theme.key_dialogRedIcon));
    }
}
Also used : ArrayList(java.util.ArrayList) BottomSheet(org.telegram.ui.ActionBar.BottomSheet)

Example 4 with BottomSheet

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

the class ArticleViewer method showCopyPopup.

private void showCopyPopup(String urlFinal) {
    if (parentActivity == null) {
        return;
    }
    if (linkSheet != null) {
        linkSheet.dismiss();
        linkSheet = null;
    }
    BottomSheet.Builder builder = new BottomSheet.Builder(parentActivity);
    builder.setTitle(urlFinal);
    builder.setItems(new CharSequence[] { LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy) }, (dialog, which) -> {
        if (parentActivity == null) {
            return;
        }
        if (which == 0) {
            int index;
            if ((index = urlFinal.lastIndexOf('#')) != -1) {
                String webPageUrl;
                if (!TextUtils.isEmpty(adapter[0].currentPage.cached_page.url)) {
                    webPageUrl = adapter[0].currentPage.cached_page.url.toLowerCase();
                } else {
                    webPageUrl = adapter[0].currentPage.url.toLowerCase();
                }
                String anchor;
                try {
                    anchor = URLDecoder.decode(urlFinal.substring(index + 1), "UTF-8");
                } catch (Exception ignore) {
                    anchor = "";
                }
                if (urlFinal.toLowerCase().contains(webPageUrl)) {
                    if (TextUtils.isEmpty(anchor)) {
                        layoutManager[0].scrollToPositionWithOffset(0, 0);
                        checkScrollAnimated();
                    } else {
                        scrollToAnchor(anchor);
                    }
                    return;
                }
            }
            Browser.openUrl(parentActivity, urlFinal);
        } else if (which == 1) {
            String url = urlFinal;
            if (url.startsWith("mailto:")) {
                url = url.substring(7);
            } else if (url.startsWith("tel:")) {
                url = url.substring(4);
            }
            AndroidUtilities.addToClipboard(url);
        }
    });
    BottomSheet sheet = builder.create();
    showDialog(sheet);
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 5 with BottomSheet

use of org.telegram.ui.ActionBar.BottomSheet 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

BottomSheet (org.telegram.ui.ActionBar.BottomSheet)13 SpannableStringBuilder (android.text.SpannableStringBuilder)8 SuppressLint (android.annotation.SuppressLint)6 LinearLayout (android.widget.LinearLayout)6 SharedPreferences (android.content.SharedPreferences)5 SpannableString (android.text.SpannableString)5 Manifest (android.Manifest)4 Activity (android.app.Activity)4 Dialog (android.app.Dialog)4 Context (android.content.Context)4 DialogInterface (android.content.DialogInterface)4 Intent (android.content.Intent)4 PackageManager (android.content.pm.PackageManager)4 Color (android.graphics.Color)4 PorterDuff (android.graphics.PorterDuff)4 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)4 Rect (android.graphics.Rect)4 Drawable (android.graphics.drawable.Drawable)4 ArrayList (java.util.ArrayList)4 TLRPC (org.telegram.tgnet.TLRPC)4