Search in sources :

Example 46 with ActionBarMenu

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

the class MessageStatisticActivity method updateMenu.

private void updateMenu() {
    if (chat != null && chat.can_view_stats) {
        ActionBarMenu menu = actionBar.createMenu();
        menu.clearItems();
        ActionBarMenuItem headerItem = menu.addItem(0, R.drawable.ic_ab_other);
        headerItem.addSubItem(1, R.drawable.msg_stats, LocaleController.getString("ViewChannelStats", R.string.ViewChannelStats));
    }
}
Also used : ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu)

Example 47 with ActionBarMenu

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

the class NotificationsCustomSettingsActivity method createView.

@Override
public View createView(Context context) {
    searching = false;
    searchWas = false;
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (currentType == -1) {
        actionBar.setTitle(LocaleController.getString("NotificationsExceptions", R.string.NotificationsExceptions));
    } else {
        actionBar.setTitle(LocaleController.getString("Notifications", R.string.Notifications));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    if (exceptions != null && !exceptions.isEmpty()) {
        ActionBarMenu menu = actionBar.createMenu();
        ActionBarMenuItem searchItem = menu.addItem(search_button, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

            @Override
            public void onSearchExpand() {
                searching = true;
                emptyView.setShowAtCenter(true);
            }

            @Override
            public void onSearchCollapse() {
                searchAdapter.searchDialogs(null);
                searching = false;
                searchWas = false;
                emptyView.setText(LocaleController.getString("NoExceptions", R.string.NoExceptions));
                listView.setAdapter(adapter);
                adapter.notifyDataSetChanged();
                listView.setFastScrollVisible(true);
                listView.setVerticalScrollBarEnabled(false);
                emptyView.setShowAtCenter(false);
            }

            @Override
            public void onTextChanged(EditText editText) {
                if (searchAdapter == null) {
                    return;
                }
                String text = editText.getText().toString();
                if (text.length() != 0) {
                    searchWas = true;
                    if (listView != null) {
                        emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
                        emptyView.showProgress();
                        listView.setAdapter(searchAdapter);
                        searchAdapter.notifyDataSetChanged();
                        listView.setFastScrollVisible(false);
                        listView.setVerticalScrollBarEnabled(true);
                    }
                }
                searchAdapter.searchDialogs(text);
            }
        });
        searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
    }
    searchAdapter = new SearchAdapter(context);
    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    emptyView = new EmptyTextProgressView(context);
    emptyView.setTextSize(18);
    emptyView.setText(LocaleController.getString("NoExceptions", R.string.NoExceptions));
    emptyView.showTextView();
    frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView = new RecyclerListView(context);
    listView.setEmptyView(emptyView);
    listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    listView.setVerticalScrollBarEnabled(false);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setAdapter(adapter = new ListAdapter(context));
    listView.setOnItemClickListener((view, position, x, y) -> {
        boolean enabled = false;
        if (getParentActivity() == null) {
            return;
        }
        if (listView.getAdapter() == searchAdapter || position >= exceptionsStartRow && position < exceptionsEndRow) {
            ArrayList<NotificationsSettingsActivity.NotificationException> arrayList;
            NotificationsSettingsActivity.NotificationException exception;
            boolean newException;
            if (listView.getAdapter() == searchAdapter) {
                Object object = searchAdapter.getObject(position);
                if (object instanceof NotificationsSettingsActivity.NotificationException) {
                    arrayList = searchAdapter.searchResult;
                    exception = (NotificationsSettingsActivity.NotificationException) object;
                    newException = false;
                } else {
                    long did;
                    if (object instanceof TLRPC.User) {
                        TLRPC.User user = (TLRPC.User) object;
                        did = user.id;
                    } else {
                        TLRPC.Chat chat = (TLRPC.Chat) object;
                        did = -chat.id;
                    }
                    if (exceptionsDict.containsKey(did)) {
                        exception = exceptionsDict.get(did);
                        newException = false;
                    } else {
                        newException = true;
                        exception = new NotificationsSettingsActivity.NotificationException();
                        exception.did = did;
                        if (object instanceof TLRPC.User) {
                            TLRPC.User user = (TLRPC.User) object;
                            exception.did = user.id;
                        } else {
                            TLRPC.Chat chat = (TLRPC.Chat) object;
                            exception.did = -chat.id;
                        }
                    }
                    arrayList = exceptions;
                }
            } else {
                arrayList = exceptions;
                int index = position - exceptionsStartRow;
                if (index < 0 || index >= arrayList.size()) {
                    return;
                }
                exception = arrayList.get(index);
                newException = false;
            }
            if (exception == null) {
                return;
            }
            AlertsCreator.showCustomNotificationsDialog(NotificationsCustomSettingsActivity.this, exception.did, -1, null, currentAccount, null, param -> {
                if (param == 0) {
                    if (newException) {
                        return;
                    }
                    if (arrayList != exceptions) {
                        int idx = exceptions.indexOf(exception);
                        if (idx >= 0) {
                            exceptions.remove(idx);
                            exceptionsDict.remove(exception.did);
                        }
                    }
                    arrayList.remove(exception);
                    if (arrayList == exceptions) {
                        if (exceptionsAddRow != -1 && arrayList.isEmpty()) {
                            listView.getAdapter().notifyItemChanged(exceptionsAddRow);
                            listView.getAdapter().notifyItemRemoved(deleteAllRow);
                            listView.getAdapter().notifyItemRemoved(deleteAllSectionRow);
                        }
                        listView.getAdapter().notifyItemRemoved(position);
                        updateRows(false);
                        checkRowsEnabled();
                    } else {
                        updateRows(true);
                        searchAdapter.notifyDataSetChanged();
                    }
                    actionBar.closeSearchField();
                } else {
                    SharedPreferences preferences = getNotificationsSettings();
                    exception.hasCustom = preferences.getBoolean("custom_" + exception.did, false);
                    exception.notify = preferences.getInt("notify2_" + exception.did, 0);
                    if (exception.notify != 0) {
                        int time = preferences.getInt("notifyuntil_" + exception.did, -1);
                        if (time != -1) {
                            exception.muteUntil = time;
                        }
                    }
                    if (newException) {
                        exceptions.add(exception);
                        exceptionsDict.put(exception.did, exception);
                        updateRows(true);
                    } else {
                        listView.getAdapter().notifyItemChanged(position);
                    }
                    actionBar.closeSearchField();
                }
            });
            return;
        }
        if (position == exceptionsAddRow) {
            Bundle args = new Bundle();
            args.putBoolean("onlySelect", true);
            args.putBoolean("checkCanWrite", false);
            if (currentType == NotificationsController.TYPE_GROUP) {
                args.putInt("dialogsType", 6);
            } else if (currentType == NotificationsController.TYPE_CHANNEL) {
                args.putInt("dialogsType", 5);
            } else {
                args.putInt("dialogsType", 4);
            }
            DialogsActivity activity = new DialogsActivity(args);
            activity.setDelegate((fragment, dids, message, param) -> {
                Bundle args2 = new Bundle();
                args2.putLong("dialog_id", dids.get(0));
                args2.putBoolean("exception", true);
                ProfileNotificationsActivity profileNotificationsActivity = new ProfileNotificationsActivity(args2);
                profileNotificationsActivity.setDelegate(exception -> {
                    exceptions.add(0, exception);
                    updateRows(true);
                });
                presentFragment(profileNotificationsActivity, true);
            });
            presentFragment(activity);
        } else if (position == deleteAllRow) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("NotificationsDeleteAllExceptionTitle", R.string.NotificationsDeleteAllExceptionTitle));
            builder.setMessage(LocaleController.getString("NotificationsDeleteAllExceptionAlert", R.string.NotificationsDeleteAllExceptionAlert));
            builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
                SharedPreferences preferences = getNotificationsSettings();
                SharedPreferences.Editor editor = preferences.edit();
                for (int a = 0, N = exceptions.size(); a < N; a++) {
                    NotificationsSettingsActivity.NotificationException exception = exceptions.get(a);
                    editor.remove("notify2_" + exception.did).remove("custom_" + exception.did);
                    getMessagesStorage().setDialogFlags(exception.did, 0);
                    TLRPC.Dialog dialog = getMessagesController().dialogs_dict.get(exception.did);
                    if (dialog != null) {
                        dialog.notify_settings = new TLRPC.TL_peerNotifySettings();
                    }
                }
                editor.commit();
                for (int a = 0, N = exceptions.size(); a < N; a++) {
                    NotificationsSettingsActivity.NotificationException exception = exceptions.get(a);
                    getNotificationsController().updateServerNotificationsSettings(exception.did, false);
                }
                exceptions.clear();
                exceptionsDict.clear();
                updateRows(true);
                getNotificationCenter().postNotificationName(NotificationCenter.notificationsSettingsUpdated);
            });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            AlertDialog alertDialog = builder.create();
            showDialog(alertDialog);
            TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
            if (button != null) {
                button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
            }
        } else if (position == alertRow) {
            enabled = getNotificationsController().isGlobalNotificationsEnabled(currentType);
            NotificationsCheckCell checkCell = (NotificationsCheckCell) view;
            RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(position);
            if (!enabled) {
                getNotificationsController().setGlobalNotificationsEnabled(currentType, 0);
                checkCell.setChecked(true);
                if (holder != null) {
                    adapter.onBindViewHolder(holder, position);
                }
                checkRowsEnabled();
            } else {
                AlertsCreator.showCustomNotificationsDialog(NotificationsCustomSettingsActivity.this, 0, currentType, exceptions, currentAccount, param -> {
                    int offUntil;
                    SharedPreferences preferences = getNotificationsSettings();
                    if (currentType == NotificationsController.TYPE_PRIVATE) {
                        offUntil = preferences.getInt("EnableAll2", 0);
                    } else if (currentType == NotificationsController.TYPE_GROUP) {
                        offUntil = preferences.getInt("EnableGroup2", 0);
                    } else {
                        offUntil = preferences.getInt("EnableChannel2", 0);
                    }
                    int currentTime = getConnectionsManager().getCurrentTime();
                    int iconType;
                    if (offUntil < currentTime) {
                        iconType = 0;
                    } else if (offUntil - 60 * 60 * 24 * 365 >= currentTime) {
                        iconType = 0;
                    } else {
                        iconType = 2;
                    }
                    checkCell.setChecked(getNotificationsController().isGlobalNotificationsEnabled(currentType), iconType);
                    if (holder != null) {
                        adapter.onBindViewHolder(holder, position);
                    }
                    checkRowsEnabled();
                });
            }
        } else if (position == previewRow) {
            if (!view.isEnabled()) {
                return;
            }
            SharedPreferences preferences = getNotificationsSettings();
            SharedPreferences.Editor editor = preferences.edit();
            if (currentType == NotificationsController.TYPE_PRIVATE) {
                enabled = preferences.getBoolean("EnablePreviewAll", true);
                editor.putBoolean("EnablePreviewAll", !enabled);
            } else if (currentType == NotificationsController.TYPE_GROUP) {
                enabled = preferences.getBoolean("EnablePreviewGroup", true);
                editor.putBoolean("EnablePreviewGroup", !enabled);
            } else {
                enabled = preferences.getBoolean("EnablePreviewChannel", true);
                editor.putBoolean("EnablePreviewChannel", !enabled);
            }
            editor.commit();
            getNotificationsController().updateServerNotificationsSettings(currentType);
        } else if (position == messageSoundRow) {
            if (!view.isEnabled()) {
                return;
            }
            try {
                SharedPreferences preferences = getNotificationsSettings();
                Intent tmpIntent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
                tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
                tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
                tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
                Uri currentSound = null;
                String defaultPath = null;
                Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
                if (defaultUri != null) {
                    defaultPath = defaultUri.getPath();
                }
                String path;
                if (currentType == NotificationsController.TYPE_PRIVATE) {
                    path = preferences.getString("GlobalSoundPath", defaultPath);
                } else if (currentType == NotificationsController.TYPE_GROUP) {
                    path = preferences.getString("GroupSoundPath", defaultPath);
                } else {
                    path = preferences.getString("ChannelSoundPath", defaultPath);
                }
                if (path != null && !path.equals("NoSound")) {
                    if (path.equals(defaultPath)) {
                        currentSound = defaultUri;
                    } else {
                        currentSound = Uri.parse(path);
                    }
                }
                tmpIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
                startActivityForResult(tmpIntent, position);
            } catch (Exception e) {
                FileLog.e(e);
            }
        } else if (position == messageLedRow) {
            if (!view.isEnabled()) {
                return;
            }
            showDialog(AlertsCreator.createColorSelectDialog(getParentActivity(), 0, currentType, () -> {
                RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(position);
                if (holder != null) {
                    adapter.onBindViewHolder(holder, position);
                }
            }));
        } else if (position == messagePopupNotificationRow) {
            if (!view.isEnabled()) {
                return;
            }
            showDialog(AlertsCreator.createPopupSelectDialog(getParentActivity(), currentType, () -> {
                RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(position);
                if (holder != null) {
                    adapter.onBindViewHolder(holder, position);
                }
            }));
        } else if (position == messageVibrateRow) {
            if (!view.isEnabled()) {
                return;
            }
            String key;
            if (currentType == NotificationsController.TYPE_PRIVATE) {
                key = "vibrate_messages";
            } else if (currentType == NotificationsController.TYPE_GROUP) {
                key = "vibrate_group";
            } else {
                key = "vibrate_channel";
            }
            showDialog(AlertsCreator.createVibrationSelectDialog(getParentActivity(), 0, key, () -> {
                RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(position);
                if (holder != null) {
                    adapter.onBindViewHolder(holder, position);
                }
            }));
        } else if (position == messagePriorityRow) {
            if (!view.isEnabled()) {
                return;
            }
            showDialog(AlertsCreator.createPrioritySelectDialog(getParentActivity(), 0, currentType, () -> {
                RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(position);
                if (holder != null) {
                    adapter.onBindViewHolder(holder, position);
                }
            }));
        }
        if (view instanceof TextCheckCell) {
            ((TextCheckCell) view).setChecked(!enabled);
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
        }
    });
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Ringtone(android.media.Ringtone) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Bundle(android.os.Bundle) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Animator(android.animation.Animator) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) TextCell(org.telegram.ui.Cells.TextCell) Map(java.util.Map) NotificationsCheckCell(org.telegram.ui.Cells.NotificationsCheckCell) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) NotificationsController(org.telegram.messenger.NotificationsController) TextColorCell(org.telegram.ui.Cells.TextColorCell) Utilities(org.telegram.messenger.Utilities) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) TextView(android.widget.TextView) SearchAdapterHelper(org.telegram.ui.Adapters.SearchAdapterHelper) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) LongSparseArray(android.util.LongSparseArray) Context(android.content.Context) Theme(org.telegram.ui.ActionBar.Theme) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) HeaderCell(org.telegram.ui.Cells.HeaderCell) AlertsCreator(org.telegram.ui.Components.AlertsCreator) ArrayList(java.util.ArrayList) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) TLObject(org.telegram.tgnet.TLObject) AnimatorSet(android.animation.AnimatorSet) Settings(android.provider.Settings) Build(android.os.Build) DialogInterface(android.content.DialogInterface) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) DialogObject(org.telegram.messenger.DialogObject) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) UserCell(org.telegram.ui.Cells.UserCell) R(org.telegram.messenger.R) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) SharedPreferences(android.content.SharedPreferences) ContactsController(org.telegram.messenger.ContactsController) GraySectionCell(org.telegram.ui.Cells.GraySectionCell) RingtoneManager(android.media.RingtoneManager) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) Activity(android.app.Activity) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) EditText(android.widget.EditText) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Uri(android.net.Uri) TLRPC(org.telegram.tgnet.TLRPC) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TextView(android.widget.TextView) ActionBar(org.telegram.ui.ActionBar.ActionBar) EditText(android.widget.EditText) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) Intent(android.content.Intent) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) NotificationsCheckCell(org.telegram.ui.Cells.NotificationsCheckCell) FrameLayout(android.widget.FrameLayout) TLObject(org.telegram.tgnet.TLObject) DialogObject(org.telegram.messenger.DialogObject) ChatObject(org.telegram.messenger.ChatObject) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 48 with ActionBarMenu

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

the class LoginActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == done_button) {
                onDoneButtonPressed();
            } else if (id == -1) {
                if (onBackPressed()) {
                    finishFragment();
                }
            }
        }
    });
    currentDoneType = DONE_TYPE_FLOATING;
    doneButtonVisible[DONE_TYPE_FLOATING] = true;
    doneButtonVisible[DONE_TYPE_ACTION] = false;
    ActionBarMenu menu = actionBar.createMenu();
    actionBar.setAllowOverlayTitle(true);
    doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
    doneProgressView = new ContextProgressView(context, 1);
    doneProgressView.setAlpha(0.0f);
    doneProgressView.setScaleX(0.1f);
    doneProgressView.setScaleY(0.1f);
    doneProgressView.setVisibility(View.INVISIBLE);
    doneItem.setAlpha(0.0f);
    doneItem.setScaleX(0.1f);
    doneItem.setScaleY(0.1f);
    doneItem.addView(doneProgressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    doneItem.setContentDescription(LocaleController.getString("Done", R.string.Done));
    doneItem.setVisibility(doneButtonVisible[DONE_TYPE_ACTION] ? View.VISIBLE : View.GONE);
    FrameLayout container = new FrameLayout(context) {

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            MarginLayoutParams marginLayoutParams = (MarginLayoutParams) floatingButtonContainer.getLayoutParams();
            if (Bulletin.getVisibleBulletin() != null && Bulletin.getVisibleBulletin().isShowing()) {
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                marginLayoutParams.bottomMargin = AndroidUtilities.dp(14) + Bulletin.getVisibleBulletin().getLayout().getMeasuredHeight() - AndroidUtilities.dp(10);
            } else {
                marginLayoutParams.bottomMargin = AndroidUtilities.dp(14);
            }
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    };
    fragmentView = container;
    ScrollView scrollView = new ScrollView(context) {

        @Override
        public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
            if (currentViewNum == 1 || currentViewNum == 2 || currentViewNum == 4) {
                rectangle.bottom += AndroidUtilities.dp(40);
            }
            return super.requestChildRectangleOnScreen(child, rectangle, immediate);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            scrollHeight = MeasureSpec.getSize(heightMeasureSpec) - AndroidUtilities.dp(30);
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    };
    scrollView.setFillViewport(true);
    container.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    FrameLayout frameLayout = new FrameLayout(context);
    scrollView.addView(frameLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT));
    views[0] = new PhoneView(context);
    views[1] = new LoginActivitySmsView(context, 1);
    views[2] = new LoginActivitySmsView(context, 2);
    views[3] = new LoginActivitySmsView(context, 3);
    views[4] = new LoginActivitySmsView(context, 4);
    views[5] = new LoginActivityRegisterView(context);
    views[6] = new LoginActivityPasswordView(context);
    views[7] = new LoginActivityRecoverView(context);
    views[8] = new LoginActivityResetWaitView(context);
    views[9] = new LoginActivityNewPasswordView(context, 0);
    views[10] = new LoginActivityNewPasswordView(context, 1);
    views[11] = new LoginActivitySmsView(context, 11);
    for (int a = 0; a < views.length; a++) {
        views[a].setVisibility(a == 0 ? View.VISIBLE : View.GONE);
        frameLayout.addView(views[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 26 : 18, 30, AndroidUtilities.isTablet() ? 26 : 18, 0));
    }
    Bundle savedInstanceState = loadCurrentState();
    if (savedInstanceState != null) {
        currentViewNum = savedInstanceState.getInt("currentViewNum", 0);
        syncContacts = savedInstanceState.getInt("syncContacts", 1) == 1;
        if (currentViewNum >= 1 && currentViewNum <= 4) {
            int time = savedInstanceState.getInt("open");
            if (time != 0 && Math.abs(System.currentTimeMillis() / 1000 - time) >= 24 * 60 * 60) {
                currentViewNum = 0;
                savedInstanceState = null;
                clearCurrentState();
            }
        } else if (currentViewNum == 6) {
            LoginActivityPasswordView view = (LoginActivityPasswordView) views[6];
            if (view.currentPassword == null) {
                currentViewNum = 0;
                savedInstanceState = null;
                clearCurrentState();
            }
        } else if (currentViewNum == 7) {
            LoginActivityRecoverView view = (LoginActivityRecoverView) views[7];
            if (view.passwordString == null) {
                currentViewNum = 0;
                savedInstanceState = null;
                clearCurrentState();
            }
        }
    }
    floatingButtonContainer = new FrameLayout(context);
    floatingButtonContainer.setVisibility(doneButtonVisible[DONE_TYPE_FLOATING] ? View.VISIBLE : View.GONE);
    Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_chats_actionBackground), Theme.getColor(Theme.key_chats_actionPressedBackground));
    if (Build.VERSION.SDK_INT < 21) {
        Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow).mutate();
        shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
        CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0);
        combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
        drawable = combinedDrawable;
    }
    floatingButtonContainer.setBackgroundDrawable(drawable);
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator.ofFloat(floatingButtonIcon, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
        animator.addState(new int[] {}, ObjectAnimator.ofFloat(floatingButtonIcon, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
        floatingButtonContainer.setStateListAnimator(animator);
        floatingButtonContainer.setOutlineProvider(new ViewOutlineProvider() {

            @SuppressLint("NewApi")
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            }
        });
    }
    VerticalPositionAutoAnimator.attach(floatingButtonContainer);
    container.addView(floatingButtonContainer, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 14, 14));
    floatingButtonContainer.setOnClickListener(view -> onDoneButtonPressed());
    floatingButtonIcon = new ImageView(context);
    floatingButtonIcon.setScaleType(ImageView.ScaleType.CENTER);
    floatingButtonIcon.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY));
    floatingButtonIcon.setImageResource(R.drawable.actionbtn_next);
    floatingButtonContainer.setContentDescription(LocaleController.getString("Done", R.string.Done));
    floatingButtonContainer.addView(floatingButtonIcon, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60));
    floatingProgressView = new RadialProgressView(context);
    floatingProgressView.setSize(AndroidUtilities.dp(22));
    floatingProgressView.setProgressColor(Theme.getColor(Theme.key_chats_actionIcon));
    floatingProgressView.setAlpha(0.0f);
    floatingProgressView.setScaleX(0.1f);
    floatingProgressView.setScaleY(0.1f);
    floatingProgressView.setVisibility(View.INVISIBLE);
    floatingButtonContainer.addView(floatingProgressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    if (savedInstanceState != null) {
        restoringState = true;
    }
    for (int a = 0; a < views.length; a++) {
        if (savedInstanceState != null) {
            if (a >= 1 && a <= 4) {
                if (a == currentViewNum) {
                    views[a].restoreStateParams(savedInstanceState);
                }
            } else {
                views[a].restoreStateParams(savedInstanceState);
            }
        }
        if (currentViewNum == a) {
            actionBar.setBackButtonImage(views[a].needBackButton() || newAccount ? R.drawable.ic_ab_back : 0);
            views[a].setVisibility(View.VISIBLE);
            views[a].onShow();
            currentDoneType = DONE_TYPE_FLOATING;
            if (a == 1 || a == 2 || a == 3 || a == 4 || a == 8) {
                showDoneButton(false, false);
            } else {
                showDoneButton(true, false);
            }
            if (a == 1 || a == 2 || a == 3 || a == 4) {
                currentDoneType = DONE_TYPE_ACTION;
            }
        } else {
            views[a].setVisibility(View.GONE);
        }
    }
    restoringState = false;
    actionBar.setTitle(views[currentViewNum].getHeaderName());
    return fragmentView;
}
Also used : ContextProgressView(org.telegram.ui.Components.ContextProgressView) StateListAnimator(android.animation.StateListAnimator) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) ImageView(android.widget.ImageView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) BackupImageView(org.telegram.ui.Components.BackupImageView) ActionBar(org.telegram.ui.ActionBar.ActionBar) Rect(android.graphics.Rect) RadialProgressView(org.telegram.ui.Components.RadialProgressView) Bundle(android.os.Bundle) Drawable(android.graphics.drawable.Drawable) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) Outline(android.graphics.Outline) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) SlideView(org.telegram.ui.Components.SlideView) ScrollView(android.widget.ScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) ContextProgressView(org.telegram.ui.Components.ContextProgressView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) TextView(android.widget.TextView) BackupImageView(org.telegram.ui.Components.BackupImageView) ViewOutlineProvider(android.view.ViewOutlineProvider) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) ScrollView(android.widget.ScrollView) FrameLayout(android.widget.FrameLayout) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) SuppressLint(android.annotation.SuppressLint)

Example 49 with ActionBarMenu

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

the class MemberRequestsActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setAllowOverlayTitle(true);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setTitle(delegate.isChannel ? LocaleController.getString("SubscribeRequests", R.string.SubscribeRequests) : LocaleController.getString("MemberRequests", R.string.MemberRequests));
    ActionBarMenu menu = actionBar.createMenu();
    ActionBarMenuItem searchItem = menu.addItem(searchMenuItem, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

        @Override
        public void onSearchExpand() {
            super.onSearchExpand();
            delegate.setSearchExpanded(true);
        }

        @Override
        public void onSearchCollapse() {
            super.onSearchCollapse();
            delegate.setSearchExpanded(false);
            delegate.setQuery(null);
        }

        @Override
        public void onTextChanged(EditText editText) {
            super.onTextChanged(editText);
            delegate.setQuery(editText.getText().toString());
        }
    });
    searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
    searchItem.setVisibility(View.GONE);
    FrameLayout rootLayout = delegate.getRootLayout();
    delegate.loadMembers();
    return fragmentView = rootLayout;
}
Also used : EditText(android.widget.EditText) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) FrameLayout(android.widget.FrameLayout) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) ActionBar(org.telegram.ui.ActionBar.ActionBar)

Example 50 with ActionBarMenu

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

the class ChangePhoneActivity method createView.

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

        @Override
        public void onItemClick(int id) {
            if (id == done_button) {
                views[currentViewNum].onNextPressed(null);
            } else if (id == -1) {
                finishFragment();
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
    ScrollView scrollView = new ScrollView(context) {

        @Override
        public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
            if (currentViewNum == 1 || currentViewNum == 2 || currentViewNum == 4) {
                rectangle.bottom += AndroidUtilities.dp(40);
            }
            return super.requestChildRectangleOnScreen(child, rectangle, immediate);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            scrollHeight = MeasureSpec.getSize(heightMeasureSpec) - AndroidUtilities.dp(30);
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    };
    scrollView.setFillViewport(true);
    fragmentView = scrollView;
    FrameLayout frameLayout = new FrameLayout(context);
    scrollView.addView(frameLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT));
    views[0] = new PhoneView(context);
    views[1] = new LoginActivitySmsView(context, 1);
    views[2] = new LoginActivitySmsView(context, 2);
    views[3] = new LoginActivitySmsView(context, 3);
    views[4] = new LoginActivitySmsView(context, 4);
    for (int a = 0; a < views.length; a++) {
        views[a].setVisibility(a == 0 ? View.VISIBLE : View.GONE);
        frameLayout.addView(views[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, a == 0 ? LayoutHelper.WRAP_CONTENT : LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 26 : 18, 30, AndroidUtilities.isTablet() ? 26 : 18, 0));
    }
    actionBar.setTitle(views[0].getHeaderName());
    return fragmentView;
}
Also used : Rect(android.graphics.Rect) ScrollView(android.widget.ScrollView) FrameLayout(android.widget.FrameLayout) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) TextView(android.widget.TextView) SlideView(org.telegram.ui.Components.SlideView) ScrollView(android.widget.ScrollView) ActionBar(org.telegram.ui.ActionBar.ActionBar) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Aggregations

ActionBarMenu (org.telegram.ui.ActionBar.ActionBarMenu)60 ActionBar (org.telegram.ui.ActionBar.ActionBar)52 FrameLayout (android.widget.FrameLayout)48 View (android.view.View)39 TextView (android.widget.TextView)39 TLRPC (org.telegram.tgnet.TLRPC)35 RecyclerListView (org.telegram.ui.Components.RecyclerListView)33 RecyclerView (androidx.recyclerview.widget.RecyclerView)31 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)30 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)30 Paint (android.graphics.Paint)29 ActionBarMenuItem (org.telegram.ui.ActionBar.ActionBarMenuItem)28 ArrayList (java.util.ArrayList)27 Canvas (android.graphics.Canvas)25 ViewGroup (android.view.ViewGroup)25 EditTextBoldCursor (org.telegram.ui.Components.EditTextBoldCursor)25 ImageView (android.widget.ImageView)24 LinearLayout (android.widget.LinearLayout)24 BaseFragment (org.telegram.ui.ActionBar.BaseFragment)24 Animator (android.animation.Animator)23