use of org.telegram.ui.Cells.CheckBoxCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ContactAddActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (addContact) {
actionBar.setTitle(LocaleController.getString("NewContact", R.string.NewContact));
} else {
actionBar.setTitle(LocaleController.getString("EditName", R.string.EditName));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
if (firstNameField.getText().length() != 0) {
TLRPC.User user = getMessagesController().getUser(user_id);
user.first_name = firstNameField.getText().toString();
user.last_name = lastNameField.getText().toString();
getContactsController().addContact(user, checkBoxCell != null && checkBoxCell.isChecked());
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
preferences.edit().putInt("dialog_bar_vis3" + user_id, 3).commit();
getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_NAME);
getNotificationCenter().postNotificationName(NotificationCenter.peerSettingsDidLoad, user_id);
finishFragment();
if (delegate != null) {
delegate.didAddToContacts();
}
}
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItem(done_button, LocaleController.getString("Done", R.string.Done).toUpperCase());
fragmentView = new ScrollView(context);
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
((ScrollView) fragmentView).addView(linearLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT));
linearLayout.setOnTouchListener((v, event) -> true);
FrameLayout frameLayout = new FrameLayout(context);
linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 24, 24, 24, 0));
avatarImage = new BackupImageView(context);
avatarImage.setRoundRadius(AndroidUtilities.dp(30));
frameLayout.addView(avatarImage, LayoutHelper.createFrame(60, 60, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP));
nameTextView = new TextView(context);
nameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
nameTextView.setLines(1);
nameTextView.setMaxLines(1);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 80, 3, LocaleController.isRTL ? 80 : 0, 0));
onlineTextView = new TextView(context);
onlineTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText3));
onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
onlineTextView.setLines(1);
onlineTextView.setMaxLines(1);
onlineTextView.setSingleLine(true);
onlineTextView.setEllipsize(TextUtils.TruncateAt.END);
onlineTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
frameLayout.addView(onlineTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 80, 32, LocaleController.isRTL ? 80 : 0, 0));
firstNameField = new EditTextBoldCursor(context);
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
firstNameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
firstNameField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
firstNameField.setMaxLines(1);
firstNameField.setLines(1);
firstNameField.setSingleLine(true);
firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
firstNameField.setImeOptions(EditorInfo.IME_ACTION_NEXT);
firstNameField.setHint(LocaleController.getString("FirstName", R.string.FirstName));
firstNameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
firstNameField.setCursorSize(AndroidUtilities.dp(20));
firstNameField.setCursorWidth(1.5f);
linearLayout.addView(firstNameField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 24, 24, 24, 0));
firstNameField.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_NEXT) {
lastNameField.requestFocus();
lastNameField.setSelection(lastNameField.length());
return true;
}
return false;
});
firstNameField.setOnFocusChangeListener(new View.OnFocusChangeListener() {
boolean focued;
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!paused && !hasFocus && focued) {
FileLog.d("changed");
}
focued = hasFocus;
}
});
lastNameField = new EditTextBoldCursor(context);
lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
lastNameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
lastNameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
lastNameField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
lastNameField.setMaxLines(1);
lastNameField.setLines(1);
lastNameField.setSingleLine(true);
lastNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
lastNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
lastNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
lastNameField.setHint(LocaleController.getString("LastName", R.string.LastName));
lastNameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
lastNameField.setCursorSize(AndroidUtilities.dp(20));
lastNameField.setCursorWidth(1.5f);
linearLayout.addView(lastNameField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 24, 16, 24, 0));
lastNameField.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE) {
doneButton.performClick();
return true;
}
return false;
});
TLRPC.User user = getMessagesController().getUser(user_id);
if (user != null) {
if (user.phone == null) {
if (phone != null) {
user.phone = PhoneFormat.stripExceptNumbers(phone);
}
}
firstNameField.setText(user.first_name);
firstNameField.setSelection(firstNameField.length());
lastNameField.setText(user.last_name);
}
infoTextView = new TextView(context);
infoTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
infoTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
if (addContact) {
if (!needAddException || TextUtils.isEmpty(user.phone)) {
linearLayout.addView(infoTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 24, 18, 24, 0));
}
if (needAddException) {
checkBoxCell = new CheckBoxCell(getParentActivity(), 0);
checkBoxCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
checkBoxCell.setText(LocaleController.formatString("SharePhoneNumberWith", R.string.SharePhoneNumberWith, UserObject.getFirstName(user)), "", true, false);
checkBoxCell.setPadding(AndroidUtilities.dp(7), 0, AndroidUtilities.dp(7), 0);
checkBoxCell.setOnClickListener(v -> checkBoxCell.setChecked(!checkBoxCell.isChecked(), true));
linearLayout.addView(checkBoxCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 10, 0, 0));
}
}
return fragmentView;
}
use of org.telegram.ui.Cells.CheckBoxCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class GroupCreateActivity method onDonePressed.
private boolean onDonePressed(boolean alert) {
if (selectedContacts.size() == 0 && chatType != ChatObject.CHAT_TYPE_CHANNEL) {
return false;
}
if (alert && addToGroup) {
if (getParentActivity() == null) {
return false;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
if (selectedContacts.size() == 1) {
builder.setTitle(LocaleController.getString("AddOneMemberAlertTitle", R.string.AddOneMemberAlertTitle));
} else {
builder.setTitle(LocaleController.formatString("AddMembersAlertTitle", R.string.AddMembersAlertTitle, LocaleController.formatPluralString("Members", selectedContacts.size())));
}
StringBuilder stringBuilder = new StringBuilder();
for (int a = 0; a < selectedContacts.size(); a++) {
long uid = selectedContacts.keyAt(a);
TLRPC.User user = getMessagesController().getUser(uid);
if (user == null) {
continue;
}
if (stringBuilder.length() > 0) {
stringBuilder.append(", ");
}
stringBuilder.append("**").append(ContactsController.formatName(user.first_name, user.last_name)).append("**");
}
TLRPC.Chat chat = getMessagesController().getChat(chatId != 0 ? chatId : channelId);
if (selectedContacts.size() > 5) {
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(AndroidUtilities.replaceTags(LocaleController.formatString("AddMembersAlertNamesText", R.string.AddMembersAlertNamesText, LocaleController.formatPluralString("Members", selectedContacts.size()), chat == null ? "" : chat.title)));
String countString = String.format("%d", selectedContacts.size());
int index = TextUtils.indexOf(spannableStringBuilder, countString);
if (index >= 0) {
spannableStringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), index, index + countString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
builder.setMessage(spannableStringBuilder);
} else {
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("AddMembersAlertNamesText", R.string.AddMembersAlertNamesText, stringBuilder, chat == null ? "" : chat.title)));
}
CheckBoxCell[] cells = new CheckBoxCell[1];
if (!ChatObject.isChannel(chat)) {
LinearLayout linearLayout = new LinearLayout(getParentActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
cells[0] = new CheckBoxCell(getParentActivity(), 1);
cells[0].setBackgroundDrawable(Theme.getSelectorDrawable(false));
cells[0].setMultiline(true);
if (selectedContacts.size() == 1) {
TLRPC.User user = getMessagesController().getUser(selectedContacts.keyAt(0));
cells[0].setText(AndroidUtilities.replaceTags(LocaleController.formatString("AddOneMemberForwardMessages", R.string.AddOneMemberForwardMessages, UserObject.getFirstName(user))), "", true, false);
} else {
cells[0].setText(LocaleController.getString("AddMembersForwardMessages", R.string.AddMembersForwardMessages), "", true, false);
}
cells[0].setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
linearLayout.addView(cells[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
cells[0].setOnClickListener(v -> cells[0].setChecked(!cells[0].isChecked(), true));
builder.setCustomViewOffset(12);
builder.setView(linearLayout);
}
builder.setPositiveButton(LocaleController.getString("Add", R.string.Add), (dialogInterface, i) -> onAddToGroupDone(cells[0] != null && cells[0].isChecked() ? 100 : 0));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
} else {
if (chatType == ChatObject.CHAT_TYPE_CHANNEL) {
ArrayList<TLRPC.InputUser> result = new ArrayList<>();
for (int a = 0; a < selectedContacts.size(); a++) {
TLRPC.InputUser user = getMessagesController().getInputUser(getMessagesController().getUser(selectedContacts.keyAt(a)));
if (user != null) {
result.add(user);
}
}
getMessagesController().addUsersToChannel(chatId, result, null);
getNotificationCenter().postNotificationName(NotificationCenter.closeChats);
Bundle args2 = new Bundle();
args2.putLong("chat_id", chatId);
presentFragment(new ChatActivity(args2), true);
} else {
if (!doneButtonVisible || selectedContacts.size() == 0) {
return false;
}
if (addToGroup) {
onAddToGroupDone(0);
} else {
ArrayList<Long> result = new ArrayList<>();
for (int a = 0; a < selectedContacts.size(); a++) {
result.add(selectedContacts.keyAt(a));
}
if (isAlwaysShare || isNeverShare) {
if (delegate != null) {
delegate.didSelectUsers(result);
}
finishFragment();
} else {
Bundle args = new Bundle();
long[] array = new long[result.size()];
for (int a = 0; a < array.length; a++) {
array[a] = result.get(a);
}
args.putLongArray("result", array);
args.putInt("chatType", chatType);
args.putBoolean("forImport", forImport);
presentFragment(new GroupCreateFinalActivity(args));
}
}
}
}
return true;
}
use of org.telegram.ui.Cells.CheckBoxCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class PassportActivity method createDocumentDeleteAlert.
private void createDocumentDeleteAlert() {
final boolean[] checks = new boolean[] { true };
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialog, which) -> {
if (!documentOnly) {
currentValues.clear();
}
currentDocumentValues.clear();
delegate.deleteValue(currentType, currentDocumentsType, availableDocumentTypes, checks[0], null, null);
finishFragment();
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
if (documentOnly && currentDocumentsType == null && currentType.type instanceof TLRPC.TL_secureValueTypeAddress) {
builder.setMessage(LocaleController.getString("PassportDeleteAddressAlert", R.string.PassportDeleteAddressAlert));
} else if (documentOnly && currentDocumentsType == null && currentType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
builder.setMessage(LocaleController.getString("PassportDeletePersonalAlert", R.string.PassportDeletePersonalAlert));
} else {
builder.setMessage(LocaleController.getString("PassportDeleteDocumentAlert", R.string.PassportDeleteDocumentAlert));
}
if (!documentOnly && currentDocumentsType != null) {
FrameLayout frameLayout = new FrameLayout(getParentActivity());
CheckBoxCell cell = new CheckBoxCell(getParentActivity(), 1);
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
if (currentType.type instanceof TLRPC.TL_secureValueTypeAddress) {
cell.setText(LocaleController.getString("PassportDeleteDocumentAddress", R.string.PassportDeleteDocumentAddress), "", true, false);
} else if (currentType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
cell.setText(LocaleController.getString("PassportDeleteDocumentPersonal", R.string.PassportDeleteDocumentPersonal), "", true, false);
}
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT));
cell.setOnClickListener(v -> {
if (!v.isEnabled()) {
return;
}
CheckBoxCell cell1 = (CheckBoxCell) v;
checks[0] = !checks[0];
cell1.setChecked(checks[0], true);
});
builder.setView(frameLayout);
}
showDialog(builder.create());
}
use of org.telegram.ui.Cells.CheckBoxCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class SessionsActivity method createView.
@Override
public View createView(Context context) {
globalFlickerLoadingView = new FlickerLoadingView(context);
globalFlickerLoadingView.setIsSingleCell(true);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (currentType == 0) {
actionBar.setTitle(LocaleController.getString("Devices", R.string.Devices));
} else {
actionBar.setTitle(LocaleController.getString("WebSessionsTitle", R.string.WebSessionsTitle));
}
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));
emptyLayout = new LinearLayout(context);
emptyLayout.setOrientation(LinearLayout.VERTICAL);
emptyLayout.setGravity(Gravity.CENTER);
emptyLayout.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
emptyLayout.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight()));
imageView = new ImageView(context);
if (currentType == 0) {
imageView.setImageResource(R.drawable.devices);
} else {
imageView.setImageResource(R.drawable.no_apps);
}
imageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_sessions_devicesImage), PorterDuff.Mode.MULTIPLY));
emptyLayout.addView(imageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
textView1 = new TextView(context);
textView1.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
textView1.setGravity(Gravity.CENTER);
textView1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
textView1.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
if (currentType == 0) {
textView1.setText(LocaleController.getString("NoOtherSessions", R.string.NoOtherSessions));
} else {
textView1.setText(LocaleController.getString("NoOtherWebSessions", R.string.NoOtherWebSessions));
}
emptyLayout.addView(textView1, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 16, 0, 0));
textView2 = new TextView(context);
textView2.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
textView2.setGravity(Gravity.CENTER);
textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
textView2.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0);
if (currentType == 0) {
textView2.setText(LocaleController.getString("NoOtherSessionsInfo", R.string.NoOtherSessionsInfo));
} else {
textView2.setText(LocaleController.getString("NoOtherWebSessionsInfo", R.string.NoOtherWebSessionsInfo));
}
emptyLayout.addView(textView2, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 14, 0, 0));
emptyView = new EmptyTextProgressView(context);
emptyView.showProgress();
frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));
listView = new RecyclerListView(context);
listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
listView.setVerticalScrollBarEnabled(false);
listView.setEmptyView(emptyView);
listView.setAnimateEmptyView(true, 0);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setAdapter(listAdapter);
listView.setOnItemClickListener((view, position) -> {
if (position == ttlRow) {
if (getParentActivity() == null) {
return;
}
int selected;
if (ttlDays <= 7) {
selected = 0;
} else if (ttlDays <= 93) {
selected = 1;
} else if (ttlDays <= 183) {
selected = 2;
} else {
selected = 3;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("SessionsSelfDestruct", R.string.SessionsSelfDestruct));
String[] items = new String[] { LocaleController.formatPluralString("Weeks", 1), LocaleController.formatPluralString("Months", 3), LocaleController.formatPluralString("Months", 6), LocaleController.formatPluralString("Years", 1) };
final LinearLayout linearLayout = new LinearLayout(getParentActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
builder.setView(linearLayout);
for (int a = 0; a < items.length; a++) {
RadioColorCell cell = new RadioColorCell(getParentActivity());
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
cell.setTag(a);
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
cell.setTextAndValue(items[a], selected == a);
linearLayout.addView(cell);
cell.setOnClickListener(v -> {
builder.getDismissRunnable().run();
Integer which = (Integer) v.getTag();
int value = 0;
if (which == 0) {
value = 7;
} else if (which == 1) {
value = 90;
} else if (which == 2) {
value = 183;
} else if (which == 3) {
value = 365;
}
final TLRPC.TL_account_setAuthorizationTTL req = new TLRPC.TL_account_setAuthorizationTTL();
req.authorization_ttl_days = value;
ttlDays = value;
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
getConnectionsManager().sendRequest(req, (response, error) -> {
});
});
}
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
} else if (position == terminateAllSessionsRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
String buttonText;
if (currentType == 0) {
builder.setMessage(LocaleController.getString("AreYouSureSessions", R.string.AreYouSureSessions));
builder.setTitle(LocaleController.getString("AreYouSureSessionsTitle", R.string.AreYouSureSessionsTitle));
buttonText = LocaleController.getString("Terminate", R.string.Terminate);
} else {
builder.setMessage(LocaleController.getString("AreYouSureWebSessions", R.string.AreYouSureWebSessions));
builder.setTitle(LocaleController.getString("TerminateWebSessionsTitle", R.string.TerminateWebSessionsTitle));
buttonText = LocaleController.getString("Disconnect", R.string.Disconnect);
}
builder.setPositiveButton(buttonText, (dialogInterface, i) -> {
if (currentType == 0) {
TLRPC.TL_auth_resetAuthorizations req = new TLRPC.TL_auth_resetAuthorizations();
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
AndroidUtilities.runOnUIThread(() -> {
if (getParentActivity() == null) {
return;
}
if (error == null && response instanceof TLRPC.TL_boolTrue) {
Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("TerminateAllSessions", R.string.TerminateAllSessions), Toast.LENGTH_SHORT);
toast.show();
finishFragment();
}
});
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
UserConfig userConfig = UserConfig.getInstance(a);
if (!userConfig.isClientActivated()) {
continue;
}
userConfig.registeredForPush = false;
userConfig.saveConfig(false);
MessagesController.getInstance(a).registerForPush(SharedConfig.pushString);
ConnectionsManager.getInstance(a).setUserId(userConfig.getClientUserId());
}
});
} else {
TLRPC.TL_account_resetWebAuthorizations req = new TLRPC.TL_account_resetWebAuthorizations();
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (getParentActivity() == null) {
return;
}
if (error == null && response instanceof TLRPC.TL_boolTrue) {
Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("TerminateAllWebSessions", R.string.TerminateAllWebSessions), Toast.LENGTH_SHORT);
toast.show();
} else {
Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("UnknownError", R.string.UnknownError), Toast.LENGTH_SHORT);
toast.show();
}
finishFragment();
}));
}
});
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 >= otherSessionsStartRow && position < otherSessionsEndRow || position >= passwordSessionsStartRow && position < passwordSessionsEndRow || position == currentSessionRow) {
if (getParentActivity() == null) {
return;
}
if (currentType == 0) {
final TLRPC.TL_authorization authorization;
boolean isCurrentSession = false;
if (position == currentSessionRow) {
authorization = currentSession;
isCurrentSession = true;
} else if (position >= otherSessionsStartRow && position < otherSessionsEndRow) {
authorization = (TLRPC.TL_authorization) sessions.get(position - otherSessionsStartRow);
} else {
authorization = (TLRPC.TL_authorization) passwordSessions.get(position - passwordSessionsStartRow);
}
showSessionBottomSheet(authorization, isCurrentSession);
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
final boolean[] param = new boolean[1];
String buttonText;
if (currentType == 0) {
builder.setMessage(LocaleController.getString("TerminateSessionText", R.string.TerminateSessionText));
builder.setTitle(LocaleController.getString("AreYouSureSessionTitle", R.string.AreYouSureSessionTitle));
buttonText = LocaleController.getString("Terminate", R.string.Terminate);
} else {
final TLRPC.TL_webAuthorization authorization = (TLRPC.TL_webAuthorization) sessions.get(position - otherSessionsStartRow);
builder.setMessage(LocaleController.formatString("TerminateWebSessionText", R.string.TerminateWebSessionText, authorization.domain));
builder.setTitle(LocaleController.getString("TerminateWebSessionTitle", R.string.TerminateWebSessionTitle));
buttonText = LocaleController.getString("Disconnect", R.string.Disconnect);
FrameLayout frameLayout1 = new FrameLayout(getParentActivity());
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(authorization.bot_id);
String name;
if (user != null) {
name = UserObject.getFirstName(user);
} else {
name = "";
}
CheckBoxCell cell = new CheckBoxCell(getParentActivity(), 1);
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
cell.setText(LocaleController.formatString("TerminateWebSessionStop", R.string.TerminateWebSessionStop, name), "", false, false);
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
frameLayout1.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 0));
cell.setOnClickListener(v -> {
if (!v.isEnabled()) {
return;
}
CheckBoxCell cell1 = (CheckBoxCell) v;
param[0] = !param[0];
cell1.setChecked(param[0], true);
});
builder.setCustomViewOffset(16);
builder.setView(frameLayout1);
}
builder.setPositiveButton(buttonText, (dialogInterface, option) -> {
if (getParentActivity() == null) {
return;
}
final AlertDialog progressDialog = new AlertDialog(getParentActivity(), 3);
progressDialog.setCanCacnel(false);
progressDialog.show();
if (currentType == 0) {
final TLRPC.TL_authorization authorization;
if (position >= otherSessionsStartRow && position < otherSessionsEndRow) {
authorization = (TLRPC.TL_authorization) sessions.get(position - otherSessionsStartRow);
} else {
authorization = (TLRPC.TL_authorization) passwordSessions.get(position - passwordSessionsStartRow);
}
TLRPC.TL_account_resetAuthorization req = new TLRPC.TL_account_resetAuthorization();
req.hash = authorization.hash;
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
if (error == null) {
sessions.remove(authorization);
passwordSessions.remove(authorization);
updateRows();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
}));
} else {
final TLRPC.TL_webAuthorization authorization = (TLRPC.TL_webAuthorization) sessions.get(position - otherSessionsStartRow);
TLRPC.TL_account_resetWebAuthorization req = new TLRPC.TL_account_resetWebAuthorization();
req.hash = authorization.hash;
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
if (error == null) {
sessions.remove(authorization);
updateRows();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
}));
if (param[0]) {
MessagesController.getInstance(currentAccount).blockPeer(authorization.bot_id);
}
}
});
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));
}
}
});
if (currentType == 0) {
undoView = new UndoView(context) {
@Override
public void hide(boolean apply, int animated) {
if (!apply) {
TLRPC.TL_authorization authorization = (TLRPC.TL_authorization) getCurrentInfoObject();
TLRPC.TL_account_resetAuthorization req = new TLRPC.TL_account_resetAuthorization();
req.hash = authorization.hash;
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (error == null) {
sessions.remove(authorization);
passwordSessions.remove(authorization);
updateRows();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
loadSessions(true);
}
}));
}
super.hide(apply, animated);
}
};
frameLayout.addView(undoView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 8, 0, 8, 8));
}
itemsEnterAnimator = new RecyclerItemsEnterAnimator(listView, true) {
@Override
public View getProgressView() {
View progressView = null;
for (int i = 0; i < listView.getChildCount(); i++) {
View child = listView.getChildAt(i);
if (listView.getChildAdapterPosition(child) >= 0 && child instanceof SessionCell && ((SessionCell) child).isStub()) {
progressView = child;
}
}
return progressView;
}
};
itemsEnterAnimator.animateAlphaProgressView = false;
updateRows();
return fragmentView;
}
use of org.telegram.ui.Cells.CheckBoxCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class PrivacySettingsActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("PrivacySettings", R.string.PrivacySettings));
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.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) {
@Override
public boolean supportsPredictiveItemAnimations() {
return false;
}
});
listView.setVerticalScrollBarEnabled(false);
listView.setItemAnimator(null);
listView.setLayoutAnimation(null);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setAdapter(listAdapter);
listView.setOnItemClickListener((view, position) -> {
if (!view.isEnabled()) {
return;
}
if (position == blockedRow) {
presentFragment(new PrivacyUsersActivity());
} else if (position == sessionsRow) {
presentFragment(new SessionsActivity(0));
} else if (position == webSessionsRow) {
presentFragment(new SessionsActivity(1));
} else if (position == deleteAccountRow) {
if (getParentActivity() == null) {
return;
}
int ttl = getContactsController().getDeleteAccountTTL();
int selected;
if (ttl <= 31) {
selected = 0;
} else if (ttl <= 93) {
selected = 1;
} else if (ttl <= 182) {
selected = 2;
} else {
selected = 3;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("DeleteAccountTitle", R.string.DeleteAccountTitle));
String[] items = new String[] { LocaleController.formatPluralString("Months", 1), LocaleController.formatPluralString("Months", 3), LocaleController.formatPluralString("Months", 6), LocaleController.formatPluralString("Years", 1) };
final LinearLayout linearLayout = new LinearLayout(getParentActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
builder.setView(linearLayout);
for (int a = 0; a < items.length; a++) {
RadioColorCell cell = new RadioColorCell(getParentActivity());
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
cell.setTag(a);
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
cell.setTextAndValue(items[a], selected == a);
linearLayout.addView(cell);
cell.setOnClickListener(v -> {
builder.getDismissRunnable().run();
Integer which = (Integer) v.getTag();
int value = 0;
if (which == 0) {
value = 30;
} else if (which == 1) {
value = 90;
} else if (which == 2) {
value = 182;
} else if (which == 3) {
value = 365;
}
final AlertDialog progressDialog = new AlertDialog(getParentActivity(), 3);
progressDialog.setCanCacnel(false);
progressDialog.show();
final TLRPC.TL_account_setAccountTTL req = new TLRPC.TL_account_setAccountTTL();
req.ttl = new TLRPC.TL_accountDaysTTL();
req.ttl.days = value;
getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
if (response instanceof TLRPC.TL_boolTrue) {
getContactsController().setDeleteAccountTTL(req.ttl.days);
listAdapter.notifyDataSetChanged();
}
}));
});
}
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
} else if (position == lastSeenRow) {
presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_LASTSEEN));
} else if (position == phoneNumberRow) {
presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_PHONE));
} else if (position == groupsRow) {
presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_INVITE));
} else if (position == callsRow) {
presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_CALLS));
} else if (position == profilePhotoRow) {
presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_PHOTO));
} else if (position == forwardsRow) {
presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_FORWARDS));
} else if (position == passwordRow) {
if (currentPassword == null) {
return;
}
if (!TwoStepVerificationActivity.canHandleCurrentPassword(currentPassword, false)) {
AlertsCreator.showUpdateAppAlert(getParentActivity(), LocaleController.getString("UpdateAppAlert", R.string.UpdateAppAlert), true);
}
if (currentPassword.has_password) {
TwoStepVerificationActivity fragment = new TwoStepVerificationActivity();
fragment.setPassword(currentPassword);
presentFragment(fragment);
} else {
int type;
if (TextUtils.isEmpty(currentPassword.email_unconfirmed_pattern)) {
type = TwoStepVerificationSetupActivity.TYPE_INTRO;
} else {
type = TwoStepVerificationSetupActivity.TYPE_EMAIL_CONFIRM;
}
presentFragment(new TwoStepVerificationSetupActivity(type, currentPassword));
}
} else if (position == passcodeRow) {
if (SharedConfig.passcodeHash.length() > 0) {
presentFragment(new PasscodeActivity(2));
} else {
presentFragment(new PasscodeActivity(0));
}
} else if (position == secretWebpageRow) {
if (getMessagesController().secretWebpagePreview == 1) {
getMessagesController().secretWebpagePreview = 0;
} else {
getMessagesController().secretWebpagePreview = 1;
}
MessagesController.getGlobalMainSettings().edit().putInt("secretWebpage2", getMessagesController().secretWebpagePreview).commit();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(getMessagesController().secretWebpagePreview == 1);
}
} else if (position == contactsDeleteRow) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("SyncContactsDeleteTitle", R.string.SyncContactsDeleteTitle));
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.getString("SyncContactsDeleteText", R.string.SyncContactsDeleteText)));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
AlertDialog.Builder builder12 = new AlertDialog.Builder(getParentActivity(), 3, null);
progressDialog = builder12.show();
progressDialog.setCanCacnel(false);
if (currentSync != newSync) {
currentSync = getUserConfig().syncContacts = newSync;
getUserConfig().saveConfig(false);
}
getContactsController().deleteAllContacts(() -> progressDialog.dismiss());
});
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 == contactsSuggestRow) {
final TextCheckCell cell = (TextCheckCell) view;
if (newSuggest) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("SuggestContactsTitle", R.string.SuggestContactsTitle));
builder.setMessage(LocaleController.getString("SuggestContactsAlert", R.string.SuggestContactsAlert));
builder.setPositiveButton(LocaleController.getString("MuteDisable", R.string.MuteDisable), (dialogInterface, i) -> {
TLRPC.TL_payments_clearSavedInfo req = new TLRPC.TL_payments_clearSavedInfo();
req.credentials = clear[1];
req.info = clear[0];
getUserConfig().tmpPassword = null;
getUserConfig().saveConfig(false);
getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
newSuggest = !newSuggest;
cell.setChecked(newSuggest);
}));
});
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 {
cell.setChecked(newSuggest = true);
}
} else if (position == newChatsRow) {
final TextCheckCell cell = (TextCheckCell) view;
archiveChats = !archiveChats;
cell.setChecked(archiveChats);
} else if (position == contactsSyncRow) {
newSync = !newSync;
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(newSync);
}
} else if (position == secretMapRow) {
AlertsCreator.showSecretLocationAlert(getParentActivity(), currentAccount, () -> listAdapter.notifyDataSetChanged(), false, null);
} else if (position == paymentsClearRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("PrivacyPaymentsClearAlertTitle", R.string.PrivacyPaymentsClearAlertTitle));
builder.setMessage(LocaleController.getString("PrivacyPaymentsClearAlertText", R.string.PrivacyPaymentsClearAlertText));
LinearLayout linearLayout = new LinearLayout(getParentActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
builder.setView(linearLayout);
for (int a = 0; a < 2; a++) {
String name;
if (a == 0) {
name = LocaleController.getString("PrivacyClearShipping", R.string.PrivacyClearShipping);
} else {
name = LocaleController.getString("PrivacyClearPayment", R.string.PrivacyClearPayment);
}
clear[a] = true;
CheckBoxCell checkBoxCell = new CheckBoxCell(getParentActivity(), 1, 21, null);
checkBoxCell.setTag(a);
checkBoxCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
checkBoxCell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
linearLayout.addView(checkBoxCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
checkBoxCell.setText(name, null, true, false);
checkBoxCell.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
checkBoxCell.setOnClickListener(v -> {
CheckBoxCell cell = (CheckBoxCell) v;
int num = (Integer) cell.getTag();
clear[num] = !clear[num];
cell.setChecked(clear[num], true);
});
}
builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton), (dialogInterface, i) -> {
try {
if (visibleDialog != null) {
visibleDialog.dismiss();
}
} catch (Exception e) {
FileLog.e(e);
}
AlertDialog.Builder builder1 = new AlertDialog.Builder(getParentActivity());
builder1.setTitle(LocaleController.getString("PrivacyPaymentsClearAlertTitle", R.string.PrivacyPaymentsClearAlertTitle));
builder1.setMessage(LocaleController.getString("PrivacyPaymentsClearAlert", R.string.PrivacyPaymentsClearAlert));
builder1.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton), (dialogInterface2, i2) -> {
TLRPC.TL_payments_clearSavedInfo req = new TLRPC.TL_payments_clearSavedInfo();
req.credentials = clear[1];
req.info = clear[0];
getUserConfig().tmpPassword = null;
getUserConfig().saveConfig(false);
getConnectionsManager().sendRequest(req, (response, error) -> {
});
String text;
if (clear[0] && clear[1]) {
text = LocaleController.getString("PrivacyPaymentsPaymentShippingCleared", R.string.PrivacyPaymentsPaymentShippingCleared);
} else if (clear[0]) {
text = LocaleController.getString("PrivacyPaymentsShippingInfoCleared", R.string.PrivacyPaymentsShippingInfoCleared);
} else if (clear[1]) {
text = LocaleController.getString("PrivacyPaymentsPaymentInfoCleared", R.string.PrivacyPaymentsPaymentInfoCleared);
} else {
return;
}
BulletinFactory.of(PrivacySettingsActivity.this).createSimpleBulletin(R.raw.chats_infotip, text).show();
});
builder1.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder1.create());
AlertDialog alertDialog = builder1.create();
showDialog(alertDialog);
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
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 == passportRow) {
presentFragment(new PassportActivity(PassportActivity.TYPE_PASSWORD, 0, "", "", null, null, null, null, null));
}
});
return fragmentView;
}
Aggregations