Skip to content

Commit

Permalink
Drawer Clean-Up and Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
immat0x1 committed May 15, 2023
1 parent 4c33350 commit e50a7b8
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.SharedConfig;
import org.telegram.messenger.UserConfig;
import org.telegram.tgnet.TLRPC;

import java.util.Arrays;
Expand Down Expand Up @@ -56,7 +58,7 @@ public class ExteraConfig {

public static int eventType;
public static boolean alternativeOpenAnimation;
public static boolean changeStatus, newGroup, newSecretChat, newChannel, contacts, calls, peopleNearby, archivedChats, savedMessages, scanQr, inviteFriends, telegramFeatures;
public static boolean changeStatus, newGroup, newSecretChat, newChannel, contacts, calls, peopleNearby, archivedChats, savedMessages, scanQr;

// General
public static int cameraType;
Expand Down Expand Up @@ -202,13 +204,11 @@ public static void loadConfig() {
newSecretChat = preferences.getBoolean("newSecretChat", false);
newChannel = preferences.getBoolean("newChannel", false);
contacts = preferences.getBoolean("contacts", true);
calls = preferences.getBoolean("calls", false);
calls = preferences.getBoolean("calls", true);
peopleNearby = preferences.getBoolean("peopleNearby", false);
archivedChats = preferences.getBoolean("archivedChats", true);
savedMessages = preferences.getBoolean("savedMessages", true);
scanQr = preferences.getBoolean("scanQr", true);
inviteFriends = preferences.getBoolean("inviteFriends", false);
telegramFeatures = preferences.getBoolean("telegramFeatures", true);

// Chats
stickerSize = preferences.getFloat("stickerSize", 14.0f);
Expand Down Expand Up @@ -315,15 +315,10 @@ public static void toggleDrawerElements(int id) {
editor.putBoolean("scanQr", scanQr ^= true).apply();
break;
case 10:
editor.putBoolean("inviteFriends", inviteFriends ^= true).apply();
break;
case 11:
editor.putBoolean("telegramFeatures", telegramFeatures ^= true).apply();
break;
case 12:
editor.putBoolean("changeStatus", changeStatus ^= true).apply();
break;
}
NotificationCenter.getInstance(UserConfig.selectedAccount).postNotificationName(NotificationCenter.mainUserInfoChanged);
}

public static void setChannelToSave(long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public class IconSetsController {
solar.put(R.drawable.list_secret, R.drawable.list_secret_solar);
solar.put(R.drawable.menu_devices, R.drawable.msg_devices_solar);
solar.put(R.drawable.msg2_animations, R.drawable.msg_played_solar);
solar.put(R.drawable.msg2_archived_stickers, R.drawable.msg_archive);
solar.put(R.drawable.msg2_archived_stickers, R.drawable.msg_archive_solar);
solar.put(R.drawable.msg2_ask_question, R.drawable.msg_ask_question_solar);
solar.put(R.drawable.msg2_ask_question, R.drawable.msg_ask_question_solar);
solar.put(R.drawable.msg2_autodelete, R.drawable.msg_autodelete_solar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.exteragram.messenger.preferences.components.MainScreenSetupCell;
import com.exteragram.messenger.preferences.components.SolarIconsPreview;
import com.exteragram.messenger.utils.AppUtils;
import com.exteragram.messenger.utils.ChatUtils;
import com.exteragram.messenger.utils.LocaleUtils;
import com.exteragram.messenger.utils.SystemUtils;
import com.exteragram.messenger.utils.PopupUtils;
Expand Down Expand Up @@ -114,8 +115,6 @@ public class AppearancePreferencesActivity extends BasePreferencesActivity {
private int archivedChatsRow;
private int savedMessagesRow;
private int scanQrRow;
private int inviteFriendsRow;
private int telegramFeaturesRow;
private int drawerDividerRow;

@Override
Expand Down Expand Up @@ -155,7 +154,7 @@ protected void updateRowsId() {

drawerHeaderRow = newRow();
statusRow = getUserConfig().isPremium() ? newRow() : -1;
archivedChatsRow = newRow();
archivedChatsRow = ChatUtils.hasArchivedChats() ? newRow() : -1;
newGroupRow = newRow();
newSecretChatRow = newRow();
newChannelRow = newRow();
Expand All @@ -164,8 +163,6 @@ protected void updateRowsId() {
peopleNearbyRow = SystemUtils.hasGps() ? newRow() : -1;
savedMessagesRow = newRow();
scanQrRow = newRow();
inviteFriendsRow = newRow();
telegramFeaturesRow = newRow();
drawerDividerRow = newRow();
}

Expand Down Expand Up @@ -230,53 +227,35 @@ protected void onItemClick(View view, int position, float x, float y) {
parentLayout.rebuildAllFragmentViews(true, true);
getListView().getLayoutManager().onRestoreInstanceState(recyclerViewState);
} else if (position == statusRow) {
ExteraConfig.toggleDrawerElements(12);
ExteraConfig.toggleDrawerElements(10);
((TextCell) view).setChecked(ExteraConfig.changeStatus);
parentLayout.rebuildAllFragmentViews(false, false);
} else if (position == newGroupRow) {
ExteraConfig.toggleDrawerElements(1);
((TextCell) view).setChecked(ExteraConfig.newGroup);
parentLayout.rebuildAllFragmentViews(false, false);
} else if (position == newSecretChatRow) {
ExteraConfig.toggleDrawerElements(2);
((TextCell) view).setChecked(ExteraConfig.newSecretChat);
parentLayout.rebuildAllFragmentViews(false, false);
} else if (position == newChannelRow) {
ExteraConfig.toggleDrawerElements(3);
((TextCell) view).setChecked(ExteraConfig.newChannel);
parentLayout.rebuildAllFragmentViews(false, false);
} else if (position == contactsRow) {
ExteraConfig.toggleDrawerElements(4);
((TextCell) view).setChecked(ExteraConfig.contacts);
parentLayout.rebuildAllFragmentViews(false, false);
} else if (position == callsRow) {
ExteraConfig.toggleDrawerElements(5);
((TextCell) view).setChecked(ExteraConfig.calls);
parentLayout.rebuildAllFragmentViews(false, false);
} else if (position == peopleNearbyRow) {
ExteraConfig.toggleDrawerElements(6);
((TextCell) view).setChecked(ExteraConfig.peopleNearby);
parentLayout.rebuildAllFragmentViews(false, false);
} else if (position == archivedChatsRow) {
ExteraConfig.toggleDrawerElements(7);
((TextCell) view).setChecked(ExteraConfig.archivedChats);
parentLayout.rebuildAllFragmentViews(false, false);
} else if (position == savedMessagesRow) {
ExteraConfig.toggleDrawerElements(8);
((TextCell) view).setChecked(ExteraConfig.savedMessages);
parentLayout.rebuildAllFragmentViews(false, false);
} else if (position == scanQrRow) {
ExteraConfig.toggleDrawerElements(9);
((TextCell) view).setChecked(ExteraConfig.scanQr);
parentLayout.rebuildAllFragmentViews(false, false);
} else if (position == inviteFriendsRow) {
ExteraConfig.toggleDrawerElements(10);
((TextCell) view).setChecked(ExteraConfig.inviteFriends);
parentLayout.rebuildAllFragmentViews(false, false);
} else if (position == telegramFeaturesRow) {
ExteraConfig.toggleDrawerElements(11);
((TextCell) view).setChecked(ExteraConfig.telegramFeatures);
parentLayout.rebuildAllFragmentViews(false, false);
} else if (position == forceSnowRow) {
ExteraConfig.editor.putBoolean("forceSnow", ExteraConfig.forceSnow ^= true).apply();
((TextCheckCell) view).setChecked(ExteraConfig.forceSnow);
Expand All @@ -291,7 +270,7 @@ protected void onItemClick(View view, int position, float x, float y) {
}, LocaleController.getString("DrawerIconSet", R.string.DrawerIconSet), ExteraConfig.eventType, getContext(), which -> {
ExteraConfig.editor.putInt("eventType", ExteraConfig.eventType = which).apply();
listAdapter.notifyItemChanged(eventChooserRow, payload);
listAdapter.notifyItemRangeChanged(statusRow, 12);
listAdapter.notifyItemRangeChanged(statusRow, 10);
getNotificationCenter().postNotificationName(NotificationCenter.mainUserInfoChanged);
});
} else if (position == hideActionBarStatusRow) {
Expand Down Expand Up @@ -454,17 +433,13 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
} else if (position == callsRow) {
textCell.setTextAndCheckAndIcon(LocaleController.getString("Calls", R.string.Calls), ExteraConfig.calls, icons[4], true);
} else if (position == peopleNearbyRow) {
textCell.setTextAndCheckAndIcon(LocaleController.getString("PeopleNearby", R.string.PeopleNearby), ExteraConfig.peopleNearby, icons[8], true);
textCell.setTextAndCheckAndIcon(LocaleController.getString("PeopleNearby", R.string.PeopleNearby), ExteraConfig.peopleNearby, icons[6], true);
} else if (position == archivedChatsRow) {
textCell.setTextAndCheckAndIcon(LocaleController.getString("ArchivedChats", R.string.ArchivedChats), ExteraConfig.archivedChats, R.drawable.msg_archive, true);
} else if (position == savedMessagesRow) {
textCell.setTextAndCheckAndIcon(LocaleController.getString("SavedMessages", R.string.SavedMessages), ExteraConfig.savedMessages, icons[5], true);
} else if (position == scanQrRow) {
textCell.setTextAndCheckAndIcon(LocaleController.getString("AuthAnotherClient", R.string.AuthAnotherClient), ExteraConfig.scanQr, R.drawable.msg_qrcode, true);
} else if (position == inviteFriendsRow) {
textCell.setTextAndCheckAndIcon(LocaleController.getString("InviteFriends", R.string.InviteFriends), ExteraConfig.inviteFriends, icons[6], true);
} else if (position == telegramFeaturesRow) {
textCell.setTextAndCheckAndIcon(LocaleController.getString("TelegramFeatures", R.string.TelegramFeatures), ExteraConfig.telegramFeatures, icons[7], false);
textCell.setTextAndCheckAndIcon(LocaleController.getString("AuthAnotherClient", R.string.AuthAnotherClient), ExteraConfig.scanQr, R.drawable.msg_qrcode, false);
}
break;
case 7:
Expand Down Expand Up @@ -498,7 +473,7 @@ public int getItemViewType(int position) {
return 1;
} else if (position == statusRow || position == newGroupRow || position == newSecretChatRow || position == newChannelRow ||
position == contactsRow || position == callsRow || position == peopleNearbyRow || position == archivedChatsRow ||
position == savedMessagesRow || position == scanQrRow || position == inviteFriendsRow || position == telegramFeaturesRow) {
position == savedMessagesRow || position == scanQrRow) {
return 2;
} else if (position == appearanceHeaderRow || position == drawerHeaderRow || position == drawerOptionsHeaderRow || position == solarIconsHeaderRow) {
return 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;

import java.util.Calendar;
Expand Down Expand Up @@ -43,8 +42,6 @@ public static int[] getDrawerIconPack() {
R.drawable.msg_contacts_ny,
R.drawable.msg_calls_ny,
R.drawable.msg_saved_ny,
R.drawable.msg_invite_ny,
R.drawable.msg_help_ny,
R.drawable.msg_nearby_ny
};
case 1:
Expand All @@ -55,8 +52,6 @@ public static int[] getDrawerIconPack() {
R.drawable.msg_contacts_14,
R.drawable.msg_calls_14,
R.drawable.msg_saved_14,
R.drawable.msg_invite_14,
R.drawable.msg_help_14,
R.drawable.msg_nearby_14
};
case 2:
Expand All @@ -67,8 +62,6 @@ public static int[] getDrawerIconPack() {
R.drawable.msg_contacts_hw,
R.drawable.msg_calls_hw,
R.drawable.msg_saved_hw,
R.drawable.msg_invite_hw,
R.drawable.msg_help_hw,
R.drawable.msg_nearby_hw
};
default:
Expand All @@ -79,8 +72,6 @@ public static int[] getDrawerIconPack() {
R.drawable.msg_contacts,
R.drawable.msg_calls,
R.drawable.msg_saved,
R.drawable.msg_invite,
R.drawable.msg_help,
R.drawable.msg_nearby
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,8 @@ public static String getPathToMessage(MessageObject messageObject) {
}
return path;
}

public static boolean hasArchivedChats() {
return getMessagesController().dialogs_dict.get(DialogObject.makeFolderDialogId(1)) != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import androidx.recyclerview.widget.RecyclerView;

import com.exteragram.messenger.ExteraConfig;
import com.exteragram.messenger.utils.ChatUtils;
import com.exteragram.messenger.utils.SystemUtils;

import org.telegram.messenger.AndroidUtilities;
Expand Down Expand Up @@ -313,9 +314,9 @@ private void resetItems() {
} else {
items.add(new Item(15, LocaleController.getString("SetEmojiStatus", R.string.SetEmojiStatus), R.drawable.msg_status_set));
}
items.add(null); // divider
items.add(null);
}
if (ExteraConfig.archivedChats) {
if (ExteraConfig.archivedChats && ChatUtils.hasArchivedChats()) {
items.add(new Item(14, LocaleController.getString("ArchivedChats", R.string.ArchivedChats), archiveIcon));
items.add(null);
}
Expand All @@ -327,10 +328,12 @@ private void resetItems() {
if (ExteraConfig.peopleNearby && hasGps) items.add(new Item(12, LocaleController.getString("PeopleNearby", R.string.PeopleNearby), peopleNearbyIcon));
if (ExteraConfig.savedMessages) items.add(new Item(11, LocaleController.getString("SavedMessages", R.string.SavedMessages), savedIcon));
items.add(new Item(8, LocaleController.getString("Settings", R.string.Settings), settingsIcon));
if (ExteraConfig.inviteFriends || ExteraConfig.telegramFeatures || ExteraConfig.scanQr) items.add(null);
if (ExteraConfig.scanQr) items.add(new Item(16, LocaleController.getString("AuthAnotherClient", R.string.AuthAnotherClient), scanQrIcon));
if (ExteraConfig.inviteFriends) items.add(new Item(7, LocaleController.getString("InviteFriends", R.string.InviteFriends), inviteIcon));
if (ExteraConfig.telegramFeatures) items.add(new Item(13, LocaleController.getString("TelegramFeatures", R.string.TelegramFeatures), helpIcon));
if (ExteraConfig.scanQr) {
items.add(null);
items.add(new Item(16, LocaleController.getString("AuthAnotherClient", R.string.AuthAnotherClient), scanQrIcon));
}
// items.add(new Item(7, LocaleController.getString("InviteFriends", R.string.InviteFriends), inviteIcon));
// items.add(new Item(13, LocaleController.getString("TelegramFeatures", R.string.TelegramFeatures), helpIcon));
}

public int getId(int position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ private void checkCurrentAccount() {
if (currentAccount != UserConfig.selectedAccount) {
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.appDidLogout);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.mainUserInfoChanged);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.dialogsNeedReload);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.didUpdateConnectionState);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.needShowAlert);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.wasUnableToFindCurrentLocation);
Expand All @@ -1442,6 +1443,7 @@ private void checkCurrentAccount() {
currentAccount = UserConfig.selectedAccount;
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.appDidLogout);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.mainUserInfoChanged);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.dialogsNeedReload);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.didUpdateConnectionState);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.needShowAlert);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.wasUnableToFindCurrentLocation);
Expand Down Expand Up @@ -5414,6 +5416,7 @@ private void onFinish() {
if (currentAccount != -1) {
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.appDidLogout);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.mainUserInfoChanged);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.dialogsNeedReload);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.didUpdateConnectionState);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.needShowAlert);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.wasUnableToFindCurrentLocation);
Expand Down Expand Up @@ -5893,7 +5896,7 @@ public void didReceivedNotification(int id, final int account, Object... args) {
currentConnectionState = state;
updateCurrentConnectionState();
}
} else if (id == NotificationCenter.mainUserInfoChanged) {
} else if (id == NotificationCenter.mainUserInfoChanged || id == NotificationCenter.dialogsNeedReload) {
drawerLayoutAdapter.notifyDataSetChanged();
} else if (id == NotificationCenter.needShowAlert) {
final Integer reason = (Integer) args[0];
Expand Down

0 comments on commit e50a7b8

Please sign in to comment.