Show join date

This commit is contained in:
Riko Sakurauchi 2020-02-08 13:13:01 +08:00
parent 92380ecfea
commit 5975bde041
No known key found for this signature in database
GPG Key ID: 25AC0345B92902AF
9 changed files with 109 additions and 13 deletions

View File

@ -1505,6 +1505,33 @@ public class LocaleController {
return "LOC_ERR";
}
public static String formatDateJoined(long date) {
try {
date *= 1000;
Calendar rightNow = Calendar.getInstance();
int day = rightNow.get(Calendar.DAY_OF_YEAR);
int year = rightNow.get(Calendar.YEAR);
rightNow.setTimeInMillis(date);
int dateDay = rightNow.get(Calendar.DAY_OF_YEAR);
int dateYear = rightNow.get(Calendar.YEAR);
if (dateDay == day && year == dateYear) {
return LocaleController.formatString("JoinedFormatted", R.string.JoinedFormatted, LocaleController.formatString("TodayAtFormatted", R.string.TodayAtFormatted, getInstance().formatterDay.format(new Date(date))));
} else if (dateDay + 1 == day && year == dateYear) {
return LocaleController.formatString("JoinedFormatted", R.string.JoinedFormatted, LocaleController.formatString("YesterdayAtFormatted", R.string.YesterdayAtFormatted, getInstance().formatterDay.format(new Date(date))));
} else if (Math.abs(System.currentTimeMillis() - date) < 31536000000L) {
String format = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, getInstance().formatterDayMonth.format(new Date(date)), getInstance().formatterDay.format(new Date(date)));
return LocaleController.formatString("JoinedDateFormatted", R.string.JoinedDateFormatted, format);
} else {
String format = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, getInstance().formatterYear.format(new Date(date)), getInstance().formatterDay.format(new Date(date)));
return LocaleController.formatString("JoinedDateFormatted", R.string.JoinedDateFormatted, format);
}
} catch (Exception e) {
FileLog.e(e);
}
return "LOC_ERR";
}
private FastDateFormat createFormatter(Locale locale, String format, String defaultFormat) {
if (format == null || format.length() == 0) {
format = defaultFormat;

View File

@ -260,7 +260,6 @@ public class UserCell2 extends FrameLayout {
statusTextView.setText(LocaleController.formatUserStatus(currentAccount, currentUser));
}
}
avatarImageView.setImage(ImageLocation.getForUser(currentUser, false), "50_50", avatarDrawable, currentUser);
} else if (currentChat != null) {
statusTextView.setTextColor(statusColor);
if (ChatObject.isChannel(currentChat) && !currentChat.megagroup) {
@ -282,6 +281,10 @@ public class UserCell2 extends FrameLayout {
statusTextView.setText(LocaleController.getString("MegaPublic", R.string.MegaPublic));
}
}
}
if (currentUser != null) {
avatarImageView.setImage(ImageLocation.getForUser(currentUser, false), "50_50", avatarDrawable, currentUser);
} else if (currentChat != null) {
avatarImageView.setImage(ImageLocation.getForChat(currentChat, false), "50_50", avatarDrawable, currentObject);
} else {
avatarImageView.setImageDrawable(avatarDrawable);

View File

@ -10973,7 +10973,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
getMessagesController().loadChannelParticipants(currentChat.id);
}
}
if (chatFull.participants == null && chatInfo != null) {
if ((NekoConfig.showJoinDate || chatFull.participants == null) && chatInfo != null) {
chatFull.participants = chatInfo.participants;
}
}

View File

@ -40,6 +40,7 @@ import org.telegram.messenger.MessagesController;
import org.telegram.messenger.R;
import org.telegram.messenger.UserObject;
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.TLObject;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
@ -68,6 +69,8 @@ import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import tw.nekomimi.nekogram.NekoConfig;
public class ChatRightsEditActivity extends BaseFragment {
private ListAdapter listViewAdapter;
@ -76,6 +79,7 @@ public class ChatRightsEditActivity extends BaseFragment {
private int chatId;
private TLRPC.User currentUser;
private TLRPC.Chat currentChat;
private TLObject participant;
private int currentType;
private boolean isChannel;
@ -131,6 +135,11 @@ public class ChatRightsEditActivity extends BaseFragment {
private final static int done_button = 1;
public ChatRightsEditActivity(int userId, int channelId, TLRPC.TL_chatAdminRights rightsAdmin, TLRPC.TL_chatBannedRights rightsBannedDefault, TLRPC.TL_chatBannedRights rightsBanned, String rank, int type, boolean edit, boolean addingNew, TLObject part) {
this(userId, channelId, rightsAdmin, rightsBannedDefault, rightsBanned, rank, type, edit, addingNew);
participant = part;
}
public ChatRightsEditActivity(int userId, int channelId, TLRPC.TL_chatAdminRights rightsAdmin, TLRPC.TL_chatBannedRights rightsBannedDefault, TLRPC.TL_chatBannedRights rightsBanned, String rank, int type, boolean edit, boolean addingNew) {
super();
isAddingNew = addingNew;
@ -1071,7 +1080,17 @@ public class ChatRightsEditActivity extends BaseFragment {
switch (holder.getItemViewType()) {
case 0:
UserCell2 userCell2 = (UserCell2) holder.itemView;
userCell2.setData(currentUser, null, null, 0);
String status = null;
if (participant instanceof TLRPC.TL_channelParticipantCreator) {
status = LocaleController.getString("ChannelCreator", R.string.ChannelCreator);
} else if (participant instanceof TLRPC.TL_channelParticipantAdmin) {
status = LocaleController.formatDateJoined(((TLRPC.TL_channelParticipantAdmin) participant).date);
} else if (participant instanceof TLRPC.TL_channelParticipant) {
status = LocaleController.formatDateJoined(((TLRPC.TL_channelParticipant) participant).date);
} else if (participant instanceof TLRPC.TL_chatChannelParticipant) {
status = LocaleController.formatDateJoined(((TLRPC.TL_chatChannelParticipant) participant).date);
}
userCell2.setData(currentUser, null, NekoConfig.showJoinDate ? status : null, 0);
break;
case 1:
TextInfoPrivacyCell privacyCell = (TextInfoPrivacyCell) holder.itemView;

View File

@ -71,6 +71,8 @@ import java.util.Collections;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import tw.nekomimi.nekogram.NekoConfig;
public class ChatUsersActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
private ListAdapter listViewAdapter;
@ -911,7 +913,7 @@ public class ChatUsersActivity extends BaseFragment implements NotificationCente
bannedRights.invite_users = true;
bannedRights.change_info = true;
}
ChatRightsEditActivity fragment = new ChatRightsEditActivity(user_id, chatId, adminRights, defaultBannedRights, bannedRights, rank, type == TYPE_ADMIN ? ChatRightsEditActivity.TYPE_ADMIN : ChatRightsEditActivity.TYPE_BANNED, canEdit, participant == null);
ChatRightsEditActivity fragment = new ChatRightsEditActivity(user_id, chatId, adminRights, defaultBannedRights, bannedRights, rank, type == TYPE_ADMIN ? ChatRightsEditActivity.TYPE_ADMIN : ChatRightsEditActivity.TYPE_BANNED, canEdit, participant == null, participant);
fragment.setDelegate(new ChatRightsEditActivity.ChatRightsEditActivityDelegate() {
@Override
public void didSetRights(int rights, TLRPC.TL_chatAdminRights rightsAdmin, TLRPC.TL_chatBannedRights rightsBanned, String rank) {
@ -1052,7 +1054,7 @@ public class ChatUsersActivity extends BaseFragment implements NotificationCente
}
private void openRightsEdit2(int userId, int date, TLObject participant, TLRPC.TL_chatAdminRights adminRights, TLRPC.TL_chatBannedRights bannedRights, String rank, boolean canEditAdmin, int type, boolean removeFragment) {
ChatRightsEditActivity fragment = new ChatRightsEditActivity(userId, chatId, adminRights, defaultBannedRights, bannedRights, rank, type, true, false);
ChatRightsEditActivity fragment = new ChatRightsEditActivity(userId, chatId, adminRights, defaultBannedRights, bannedRights, rank, type, true, false, participant);
fragment.setDelegate(new ChatRightsEditActivity.ChatRightsEditActivityDelegate() {
@Override
public void didSetRights(int rights, TLRPC.TL_chatAdminRights rightsAdmin, TLRPC.TL_chatBannedRights rightsBanned, String rank) {
@ -1117,7 +1119,7 @@ public class ChatUsersActivity extends BaseFragment implements NotificationCente
}
private void openRightsEdit(int user_id, TLObject participant, TLRPC.TL_chatAdminRights adminRights, TLRPC.TL_chatBannedRights bannedRights, String rank, boolean canEditAdmin, int type, boolean removeFragment) {
ChatRightsEditActivity fragment = new ChatRightsEditActivity(user_id, chatId, adminRights, defaultBannedRights, bannedRights, rank, type, canEditAdmin, participant == null);
ChatRightsEditActivity fragment = new ChatRightsEditActivity(user_id, chatId, adminRights, defaultBannedRights, bannedRights, rank, type, canEditAdmin, participant == null, participant);
fragment.setDelegate(new ChatRightsEditActivity.ChatRightsEditActivityDelegate() {
@Override
public void didSetRights(int rights, TLRPC.TL_chatAdminRights rightsAdmin, TLRPC.TL_chatBannedRights rightsBanned, String rank) {
@ -1403,7 +1405,7 @@ public class ChatUsersActivity extends BaseFragment implements NotificationCente
builder.setItems(items, icons, (dialogInterface, i) -> {
if (type == TYPE_ADMIN) {
if (i == 0 && items.length == 2) {
ChatRightsEditActivity fragment = new ChatRightsEditActivity(userId, chatId, adminRights, null, null, rank, ChatRightsEditActivity.TYPE_ADMIN, true, false);
ChatRightsEditActivity fragment = new ChatRightsEditActivity(userId, chatId, adminRights, null, null, rank, ChatRightsEditActivity.TYPE_ADMIN, true, false, participant);
fragment.setDelegate(new ChatRightsEditActivity.ChatRightsEditActivityDelegate() {
@Override
public void didSetRights(int rights, TLRPC.TL_chatAdminRights rightsAdmin, TLRPC.TL_chatBannedRights rightsBanned, String rank) {
@ -1429,7 +1431,7 @@ public class ChatUsersActivity extends BaseFragment implements NotificationCente
} else if (type == TYPE_BANNED || type == TYPE_KICKED) {
if (i == 0) {
if (type == TYPE_KICKED) {
ChatRightsEditActivity fragment = new ChatRightsEditActivity(userId, chatId, null, defaultBannedRights, bannedRights, rank, ChatRightsEditActivity.TYPE_BANNED, true, false);
ChatRightsEditActivity fragment = new ChatRightsEditActivity(userId, chatId, null, defaultBannedRights, bannedRights, rank, ChatRightsEditActivity.TYPE_BANNED, true, false, participant);
fragment.setDelegate(new ChatRightsEditActivity.ChatRightsEditActivityDelegate() {
@Override
public void didSetRights(int rights, TLRPC.TL_chatAdminRights rightsAdmin, TLRPC.TL_chatBannedRights rightsBanned, String rank) {
@ -2535,6 +2537,7 @@ public class ChatUsersActivity extends BaseFragment implements NotificationCente
boolean banned;
boolean creator;
boolean admin;
String joinDate;
if (item instanceof TLRPC.ChannelParticipant) {
TLRPC.ChannelParticipant participant = (TLRPC.ChannelParticipant) item;
userId = participant.user_id;
@ -2544,6 +2547,11 @@ public class ChatUsersActivity extends BaseFragment implements NotificationCente
banned = participant instanceof TLRPC.TL_channelParticipantBanned;
creator = participant instanceof TLRPC.TL_channelParticipantCreator;
admin = participant instanceof TLRPC.TL_channelParticipantAdmin;
if (creator) {
joinDate = LocaleController.getString("ChannelCreator", R.string.ChannelCreator);
} else {
joinDate = LocaleController.formatDateJoined(participant.date);
}
} else {
TLRPC.ChatParticipant participant = (TLRPC.ChatParticipant) item;
userId = participant.user_id;
@ -2553,6 +2561,11 @@ public class ChatUsersActivity extends BaseFragment implements NotificationCente
banned = false;
creator = participant instanceof TLRPC.TL_chatParticipantCreator;
admin = participant instanceof TLRPC.TL_chatParticipantAdmin;
if (creator) {
joinDate = LocaleController.getString("ChannelCreator", R.string.ChannelCreator);
} else {
joinDate = LocaleController.formatDateJoined(participant.date);
}
}
TLRPC.User user = getMessagesController().getUser(userId);
if (user != null) {
@ -2583,7 +2596,7 @@ public class ChatUsersActivity extends BaseFragment implements NotificationCente
}
userCell.setData(user, null, role, position != lastRow - 1);
} else if (type == TYPE_USERS) {
userCell.setData(user, null, null, position != lastRow - 1);
userCell.setData(user, null, NekoConfig.showJoinDate ? joinDate : null, position != lastRow - 1);
}
}
break;

View File

@ -1795,7 +1795,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
}
private void openRightsEdit(int action, int user_id, TLRPC.ChatParticipant participant, TLRPC.TL_chatAdminRights adminRights, TLRPC.TL_chatBannedRights bannedRights, String rank) {
ChatRightsEditActivity fragment = new ChatRightsEditActivity(user_id, chat_id, adminRights, currentChat.default_banned_rights, bannedRights, rank, action, true, false);
ChatRightsEditActivity fragment = new ChatRightsEditActivity(user_id, chat_id, adminRights, currentChat.default_banned_rights, bannedRights, rank, action, true, false, participant);
fragment.setDelegate(new ChatRightsEditActivity.ChatRightsEditActivityDelegate() {
@Override
public void didSetRights(int rights, TLRPC.TL_chatAdminRights rightsAdmin, TLRPC.TL_chatBannedRights rightsBanned, String rank) {
@ -4291,6 +4291,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
}
if (part != null) {
String role;
String joinDate;
if (part instanceof TLRPC.TL_chatChannelParticipant) {
TLRPC.ChannelParticipant channelParticipant = ((TLRPC.TL_chatChannelParticipant) part).channelParticipant;
if (!TextUtils.isEmpty(channelParticipant.rank)) {
@ -4304,6 +4305,11 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
role = null;
}
}
if (channelParticipant instanceof TLRPC.TL_channelParticipantCreator) {
joinDate = LocaleController.getString("ChannelCreator", R.string.ChannelCreator);
} else {
joinDate = LocaleController.formatDateJoined(part.date);
}
} else {
if (part instanceof TLRPC.TL_chatParticipantCreator) {
role = LocaleController.getString("ChannelCreator", R.string.ChannelCreator);
@ -4312,9 +4318,14 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
} else {
role = null;
}
if (part instanceof TLRPC.TL_chatParticipantCreator) {
joinDate = LocaleController.getString("ChannelCreator", R.string.ChannelCreator);
} else {
joinDate = LocaleController.formatDateJoined(part.date);
}
}
userCell.setAdminRole(role);
userCell.setData(MessagesController.getInstance(currentAccount).getUser(part.user_id), null, null, 0, position != membersEndRow - 1);
userCell.setData(MessagesController.getInstance(currentAccount).getUser(part.user_id), null, NekoConfig.showJoinDate ? joinDate : null, 0, position != membersEndRow - 1);
}
break;
}

View File

@ -21,6 +21,7 @@ public class NekoConfig {
public static int mapPreviewProvider = 0;
public static boolean transparentStatusBar = false;
public static boolean residentNotification = false;
public static boolean showJoinDate = false;
public static boolean hideProxySponsorChannel = false;
public static boolean saveCacheToPrivateDirectory = Build.VERSION.SDK_INT >= 24;
public static float stickerSize = 14.0f;
@ -79,6 +80,7 @@ public class NekoConfig {
editor.putBoolean("fireworks", fireworks);
editor.putFloat("stickerSize", stickerSize);
editor.putBoolean("unlimitedFavedStickers", unlimitedFavedStickers);
editor.putBoolean("showJoinDate", showJoinDate);
editor.commit();
} catch (Exception e) {
@ -120,6 +122,7 @@ public class NekoConfig {
fireworks = preferences.getBoolean("fireworks", false);
stickerSize = preferences.getFloat("stickerSize", 14.0f);
unlimitedFavedStickers = preferences.getBoolean("unlimitedFavedStickers", false);
showJoinDate = preferences.getBoolean("showJoinDate", false);
configLoaded = true;
}
}
@ -339,4 +342,12 @@ public class NekoConfig {
editor.commit();
}
public static void toggleShowJoinDate() {
showJoinDate = !showJoinDate;
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("showJoinDate", showJoinDate);
editor.commit();
}
}

View File

@ -71,6 +71,7 @@ public class NekoSettingsActivity extends BaseFragment {
private int inappCameraRow;
private int useSystemEmojiRow;
private int ignoreBlockedRow;
private int showJoinDateRow;
private int mapPreviewRow;
private int stickerSizeRow;
private int messageMenuRow;
@ -172,6 +173,11 @@ public class NekoSettingsActivity extends BaseFragment {
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(NekoConfig.ignoreBlocked);
}
} else if (position == showJoinDateRow) {
NekoConfig.toggleShowJoinDate();
if (view instanceof TextCheckCell) {
((TextCheckCell) view).setChecked(NekoConfig.showJoinDate);
}
} else if (position == transparentStatusBarRow) {
NekoConfig.toggleTransparentStatusBar();
if (view instanceof TextCheckCell) {
@ -337,6 +343,7 @@ public class NekoSettingsActivity extends BaseFragment {
inappCameraRow = rowCount++;
useSystemEmojiRow = rowCount++;
ignoreBlockedRow = rowCount++;
showJoinDateRow = rowCount++;
hideProxySponsorChannelRow = rowCount++;
saveCacheToPrivateDirectoryRow = Build.VERSION.SDK_INT >= 24 ? rowCount++ : -1;
mapPreviewRow = rowCount++;
@ -745,6 +752,8 @@ public class NekoSettingsActivity extends BaseFragment {
textCell.setTextAndCheck(LocaleController.getString("TypefaceUseDefault", R.string.TypefaceUseDefault), NekoConfig.typeface == 1, true);
} else if (position == ignoreBlockedRow) {
textCell.setTextAndCheck(LocaleController.getString("IgnoreBlocked", R.string.IgnoreBlocked), NekoConfig.ignoreBlocked, true);
} else if (position == showJoinDateRow) {
textCell.setTextAndCheck(LocaleController.getString("ShowJoinDate", R.string.ShowJoinDate), NekoConfig.showJoinDate, true);
} else if (position == forceTabletRow) {
textCell.setTextAndCheck(LocaleController.getString("ForceTabletMode", R.string.ForceTabletMode), NekoConfig.forceTablet, true);
} else if (position == xmasRow) {
@ -789,7 +798,7 @@ public class NekoSettingsActivity extends BaseFragment {
@Override
public boolean isEnabled(RecyclerView.ViewHolder holder) {
int position = holder.getAdapterPosition();
return position == hidePhoneRow || position == inappCameraRow || position == ignoreBlockedRow ||
return position == hidePhoneRow || position == inappCameraRow || position == ignoreBlockedRow || position == showJoinDateRow ||
position == useSystemEmojiRow || position == ipv6Row || position == typefaceRow || position == nameOrderRow ||
position == forceTabletRow || position == mapPreviewRow || position == xmasRow || position == newYearRow ||
position == newYearEveRow || position == fireworksRow || position == transparentStatusBarRow ||
@ -842,7 +851,7 @@ public class NekoSettingsActivity extends BaseFragment {
return 2;
} else if (position == ipv6Row || position == hidePhoneRow || position == inappCameraRow ||
position == transparentStatusBarRow || position == hideProxySponsorChannelRow ||
position == ignoreBlockedRow || position == useSystemEmojiRow || position == typefaceRow ||
position == ignoreBlockedRow || position == showJoinDateRow || position == useSystemEmojiRow || position == typefaceRow ||
position == forceTabletRow || position == xmasRow || position == newYearRow || position == newYearEveRow ||
position == fireworksRow || position == saveCacheToPrivateDirectoryRow || position == unlimitedFavedStickersRow ||
position == disableFilteringRow) {

View File

@ -64,4 +64,7 @@
<string name="ExportAsJson">Export as JSON</string>
<string name="Translate">Translate</string>
<string name="ServiceByGoogle">Translation service is provided by Google</string>
<string name="JoinedFormatted">joined %1$s</string>
<string name="JoinedDateFormatted">joined on %1$s</string>
<string name="ShowJoinDate">Display join date of group members</string>
</resources>