use of org.telegram.ui.Cells.SessionCell 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;
}
Aggregations