Search in sources :

Example 1 with TextCheckbox2Cell

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

the class RestrictedLanguagesSelectActivity method createView.

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

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

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

        @Override
        public void onSearchCollapse() {
            search(null);
            searching = false;
            searchWas = false;
            if (listView != null) {
                emptyView.setVisibility(View.GONE);
                listView.setAdapter(listAdapter);
            }
        }

        @Override
        public void onTextChanged(EditText editText) {
            String text = editText.getText().toString();
            search(text);
            if (text.length() != 0) {
                searchWas = true;
                if (listView != null) {
                    listView.setAdapter(searchListViewAdapter);
                }
            } else {
                searching = false;
                searchWas = false;
                if (listView != null) {
                    emptyView.setVisibility(View.GONE);
                    listView.setAdapter(listAdapter);
                }
            }
        }
    });
    item.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
    listAdapter = new ListAdapter(context, false);
    searchListViewAdapter = new ListAdapter(context, true);
    fragmentView = new FrameLayout(context);
    fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    emptyView = new EmptyTextProgressView(context);
    emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
    emptyView.showTextView();
    emptyView.setShowAtCenter(true);
    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);
    listView.setAdapter(listAdapter);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setOnItemClickListener((view, position) -> {
        if (getParentActivity() == null || parentLayout == null || !(view instanceof TextCheckbox2Cell)) {
            return;
        }
        boolean search = listView.getAdapter() == searchListViewAdapter;
        if (!search)
            position--;
        LocaleController.LocaleInfo localeInfo;
        if (search) {
            localeInfo = searchResult.get(position);
        } else {
            localeInfo = sortedLanguages.get(position);
        }
        if (localeInfo != null) {
            LocaleController.LocaleInfo currentLocaleInfo = LocaleController.getInstance().getCurrentLocaleInfo();
            String langCode = localeInfo.pluralLangCode;
            if (langCode != null && langCode.equals(currentLocaleInfo.pluralLangCode)) {
                AndroidUtilities.shakeView(((TextCheckbox2Cell) view).checkbox, 2, 0);
                return;
            }
            boolean value = selectedLanguages.contains(langCode);
            HashSet<String> newSelectedLanguages = new HashSet<String>(selectedLanguages);
            if (value)
                newSelectedLanguages.removeIf(s -> s != null && s.equals(langCode));
            else
                newSelectedLanguages.add(langCode);
            if (newSelectedLanguages.size() == 1 && newSelectedLanguages.contains(currentLocaleInfo.pluralLangCode))
                preferences.edit().remove("translate_button_restricted_languages").apply();
            else
                preferences.edit().putStringSet("translate_button_restricted_languages", newSelectedLanguages).apply();
        }
    });
    listView.setOnItemLongClickListener((view, position) -> {
        if (getParentActivity() == null || parentLayout == null || !(view instanceof TextCheckbox2Cell)) {
            return false;
        }
        boolean search = listView.getAdapter() == searchListViewAdapter;
        if (!search)
            position--;
        LocaleController.LocaleInfo localeInfo;
        if (search) {
            localeInfo = searchResult.get(position);
        } else {
            localeInfo = sortedLanguages.get(position);
        }
        if (localeInfo == null || localeInfo.pathToFile == null || localeInfo.isRemote() && localeInfo.serverIndex != Integer.MAX_VALUE) {
            return false;
        }
        final LocaleController.LocaleInfo finalLocaleInfo = localeInfo;
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setTitle(LocaleController.getString("DeleteLocalizationTitle", R.string.DeleteLocalizationTitle));
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("DeleteLocalizationText", R.string.DeleteLocalizationText, localeInfo.name)));
        builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
            if (LocaleController.getInstance().deleteLanguage(finalLocaleInfo, currentAccount)) {
                fillLanguages();
                if (searchResult != null) {
                    searchResult.remove(finalLocaleInfo);
                }
                if (listAdapter != null) {
                    listAdapter.notifyDataSetChanged();
                }
                if (searchListViewAdapter != null) {
                    searchListViewAdapter.notifyDataSetChanged();
                }
            }
        });
        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));
        }
        return true;
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
            }
        }
    });
    return fragmentView;
}
Also used : ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Arrays(java.util.Arrays) Theme(org.telegram.ui.ActionBar.Theme) FrameLayout(android.widget.FrameLayout) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) LocaleController(org.telegram.messenger.LocaleController) Timer(java.util.Timer) HeaderCell(org.telegram.ui.Cells.HeaderCell) TextCheckbox2Cell(org.telegram.ui.Cells.TextCheckbox2Cell) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) ActionBar(org.telegram.ui.ActionBar.ActionBar) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TimerTask(java.util.TimerTask) DialogInterface(android.content.DialogInterface) TextRadioCell(org.telegram.ui.Cells.TextRadioCell) Utilities(org.telegram.messenger.Utilities) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) R(org.telegram.messenger.R) LanguageCell(org.telegram.ui.Cells.LanguageCell) Set(java.util.Set) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) ViewGroup(android.view.ViewGroup) MessagesController(org.telegram.messenger.MessagesController) NotificationCenter(org.telegram.messenger.NotificationCenter) TextView(android.widget.TextView) SharedPreferences(android.content.SharedPreferences) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Comparator(java.util.Comparator) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Collections(java.util.Collections) EditText(android.widget.EditText) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ValueAnimator(android.animation.ValueAnimator) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TextCheckbox2Cell(org.telegram.ui.Cells.TextCheckbox2Cell) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TextView(android.widget.TextView) ActionBar(org.telegram.ui.ActionBar.ActionBar) HashSet(java.util.HashSet) EditText(android.widget.EditText) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) LocaleController(org.telegram.messenger.LocaleController) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Aggregations

ValueAnimator (android.animation.ValueAnimator)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 SharedPreferences (android.content.SharedPreferences)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 EditText (android.widget.EditText)1 FrameLayout (android.widget.FrameLayout)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1