Skip to content

Commit

Permalink
chats: implement toggling pinned messages view
Browse files Browse the repository at this point in the history
  • Loading branch information
iTaysonLab committed Jan 30, 2021
1 parent 207bd21 commit dced108
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
52 changes: 52 additions & 0 deletions TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
Expand Up @@ -288,6 +288,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private StickersAdapter stickersAdapter;
private FrameLayout stickersPanel;
private ActionBarMenuSubItem muteItem;
private ActionBarMenuSubItem pinVisibilityItem;
private FrameLayout pagedownButton;
private ImageView pagedownButtonImage;
private boolean pagedownButtonShowedByScroll;
Expand Down Expand Up @@ -1008,6 +1009,7 @@ public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolea
private final static int delete_chat = 16;
private final static int share_contact = 17;
private final static int mute = 18;
private final static int change_pin_visibility = 19;
private final static int report = 21;
private final static int star = 22;
private final static int edit = 23;
Expand Down Expand Up @@ -1819,6 +1821,8 @@ public void onItemClick(final int id) {
}
} else if (id == mute) {
toggleMute(false);
} else if (id == change_pin_visibility) {
togglePinVisibility();
} else if (id == add_shortcut) {
try {
getMediaDataController().installShortcut(currentUser.id);
Expand Down Expand Up @@ -11411,6 +11415,52 @@ private void updateTitleIcons() {
muteItem.setTextAndIcon(LocaleController.getString("MuteNotifications", R.string.MuteNotifications), R.drawable.msg_mute);
}
}

boolean hasHiddenPinnedMessages = MessagesController.getNotificationsSettings(currentAccount).getInt("pin_" + dialog_id, 0) != 0;
String pinActionString = hasHiddenPinnedMessages ? LocaleController.getString("ShowPinnedMessagesAction", R.string.ShowPinnedMessagesAction) : LocaleController.getString("HidePinnedMessagesAction", R.string.HidePinnedMessagesAction);

if (pinVisibilityItem != null) {
pinVisibilityItem.setTextAndIcon(pinActionString, R.drawable.msg_pin);
} else {
pinVisibilityItem = headerItem.addSubItem(change_pin_visibility, R.drawable.msg_pin, pinActionString);
}
}

private void togglePinVisibility() {
String key = "pin_" + dialog_id;
SharedPreferences prefs = MessagesController.getNotificationsSettings(currentAccount);
boolean hasHiddenPinnedMessages = prefs.getInt(key, 0) != 0;

if (hasHiddenPinnedMessages) {
prefs.edit().remove(key).commit();
} else {
prefs.edit().putInt(key, pinnedMessageIds.get(0)).commit();

if (pinBulletin != null) {
pinBulletin.hide();
}
int tag = ++pinBullerinTag;
int pinnedCount = getPinnedMessagesCount();
pinBulletin = BulletinFactory.createUnpinAllMessagesBulletin(ChatActivity.this, pinnedCount, true,
() -> {
SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
preferences.edit().remove("pin_" + dialog_id).commit();
updatePinnedMessageView(true);
updateTitleIcons();
if (tag == pinBullerinTag) {
pinBulletin = null;
}
},
() -> {
if (tag == pinBullerinTag) {
pinBulletin = null;
}
});
pinBulletin.show();
}

updatePinnedMessageView(true);
updateTitleIcons();
}

private void checkAndUpdateAvatar() {
Expand Down Expand Up @@ -14169,6 +14219,8 @@ public void didReceivedNotification(int id, int account, final Object... args) {
getMediaDataController().loadPinnedMessages(dialog_id, 0, pinnedMessageIds.isEmpty() ? 0 : pinnedMessageIds.get(0));
loadingPinnedMessagesList = true;
}

updateTitleIcons();
}
} else if (id == NotificationCenter.userInfoDidLoad) {
Integer uid = (Integer) args[0];
Expand Down
2 changes: 2 additions & 0 deletions TMessagesProj/src/main/res/values/strings.xml
Expand Up @@ -1121,6 +1121,8 @@
<string name="ChannelPostDeleted">Sorry, this post has been removed from the discussion group.</string>
<string name="UnpinAllMessages">UNPIN ALL MESSAGES</string>
<string name="HidePinnedMessages">HIDE PINNED MESSAGES</string>
<string name="HidePinnedMessagesAction">Hide pinned messages</string>
<string name="ShowPinnedMessagesAction">Show pinned messages</string>
<string name="PinnedMessagesHidden">Pinned messages hidden</string>
<string name="PinnedMessagesHiddenInfo">You will see the bar with pinned messages only if a new message is pinned.</string>
<string name="ImportedMessage">Imported</string>
Expand Down

0 comments on commit dced108

Please sign in to comment.