Skip to content

Commit

Permalink
style: limit max account count
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Aug 19, 2024
1 parent 7b0de8f commit 49cacdd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
public class UserConfig extends BaseController {

public static int selectedAccount;
//public final static int MAX_ACCOUNT_DEFAULT_COUNT = 16;
//public final static int MAX_ACCOUNT_COUNT = 4;
public final static int MAX_ACCOUNT_DEFAULT_COUNT = 8;
public final static int MAX_ACCOUNT_COUNT = 10;

private final Object sync = new Object();
private volatile boolean configLoaded;
Expand Down
18 changes: 13 additions & 5 deletions TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,19 +592,27 @@ public boolean drawChild(Canvas canvas, View child, long drawingTime) {
drawerLayoutContainer.closeDrawer(false);
} else if (view instanceof DrawerAddCell) {
int freeAccount;
int freeAccounts = UserConfig.MAX_ACCOUNT_COUNT - SharedConfig.activeAccounts.size();
for (int account = 0; ; account++) {
if (!SharedConfig.activeAccounts.contains(account)) {
freeAccount = account;
break;
}
}
// if (!UserConfig.hasPremiumOnAccounts()) {
// freeAccounts -= (UserConfig.MAX_ACCOUNT_COUNT - UserConfig.MAX_ACCOUNT_DEFAULT_COUNT);
// }
if (freeAccount >= 0) {
if (!UserConfig.hasPremiumOnAccounts()) {
freeAccounts -= (UserConfig.MAX_ACCOUNT_COUNT - UserConfig.MAX_ACCOUNT_DEFAULT_COUNT);
}
if (freeAccounts > 0 && freeAccount >= 0) {
presentFragment(new LoginActivity(freeAccount));
drawerLayoutContainer.closeDrawer(false);
} else if (!UserConfig.hasPremiumOnAccounts()) {
if (actionBarLayout.getFragmentStack().size() > 0) {
BaseFragment fragment = actionBarLayout.getFragmentStack().get(0);
LimitReachedBottomSheet limitReachedBottomSheet = new LimitReachedBottomSheet(fragment, this, TYPE_ACCOUNTS, currentAccount, null);
fragment.showDialog(limitReachedBottomSheet);
limitReachedBottomSheet.onShowPremiumScreenRunnable = () -> drawerLayoutContainer.closeDrawer(false);
}
}
drawerLayoutContainer.closeDrawer(false);
} else if (view instanceof DrawerActionCheckCell) {
int id = drawerLayoutAdapter.getId(position);
// DrawerLayoutAdapter.CheckItem item = drawerLayoutAdapter.getItem(position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,21 @@ public void onItemClick(int id) {
listView.setOnItemClickListener((view, position, x, y) -> {
if (position == addAccountRow) {
int freeAccount;
int freeAccounts = UserConfig.MAX_ACCOUNT_COUNT - SharedConfig.activeAccounts.size();
for (int account = 0;; account++) {
if (!SharedConfig.activeAccounts.contains(account)) {
freeAccount = account;
break;
}
}
if (freeAccount >= 0) {
if (!UserConfig.hasPremiumOnAccounts()) {
freeAccounts -= (UserConfig.MAX_ACCOUNT_COUNT - UserConfig.MAX_ACCOUNT_DEFAULT_COUNT);
}
if (freeAccounts > 0 && freeAccount >= 0) {
presentFragment(new LoginActivity(freeAccount));
} else if (!UserConfig.hasPremiumOnAccounts()) {
LimitReachedBottomSheet limitReachedBottomSheet = new LimitReachedBottomSheet(this, getContext(), TYPE_ACCOUNTS, currentAccount, null);
showDialog(limitReachedBottomSheet);
}
} else if (position == passcodeRow) {
presentFragment(PasscodeActivity.determineOpenFragment());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12534,13 +12534,17 @@ private SearchResult[] onCreateSearchArray() {
new SearchResult(501, LocaleController.getString("ChangePhoneNumber", R.string.ChangePhoneNumber), 0, () -> presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_CHANGE_PHONE_NUMBER))),
new SearchResult(502, LocaleController.getString("AddAnotherAccount", R.string.AddAnotherAccount), 0, () -> {
int freeAccount;
int freeAccounts = UserConfig.MAX_ACCOUNT_COUNT - SharedConfig.activeAccounts.size();
for (int account = 0; ; account++) {
if (!SharedConfig.activeAccounts.contains(account)) {
freeAccount = account;
break;
}
}
if (freeAccount >= 0) {
if (!UserConfig.hasPremiumOnAccounts()) {
freeAccounts -= (UserConfig.MAX_ACCOUNT_COUNT - UserConfig.MAX_ACCOUNT_DEFAULT_COUNT);
}
if (freeAccounts > 0 && freeAccount >= 0) {
presentFragment(new LoginActivity(freeAccount));
}
}),
Expand Down

0 comments on commit 49cacdd

Please sign in to comment.