From 0bf0d1419a0b79ad2fbe17d8be056ecf332527be Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 19 Apr 2024 20:10:52 +0800 Subject: [PATCH] feat: show user registration date Thanks to @materialgram Co-authored-by: KUKURUZKA <60149954+KUKURUZKA165@users.noreply.github.com> --- TMessagesProj/src/main/assets/id_date.json | 502 ++++++++++++++++++ .../java/org/telegram/ui/ProfileActivity.java | 7 +- .../nagram/helper/ProfileDateHelper.kt | 70 +++ 3 files changed, 578 insertions(+), 1 deletion(-) create mode 100644 TMessagesProj/src/main/assets/id_date.json create mode 100644 TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/ProfileDateHelper.kt diff --git a/TMessagesProj/src/main/assets/id_date.json b/TMessagesProj/src/main/assets/id_date.json new file mode 100644 index 0000000000..3dd9846d9e --- /dev/null +++ b/TMessagesProj/src/main/assets/id_date.json @@ -0,0 +1,502 @@ +[ + { + "id": 1000000, + "date": 1380326400 + }, + { + "id": 2768409, + "date": 1383264000 + }, + { + "id": 7679610, + "date": 1388448000 + }, + { + "id": 11538514, + "date": 1391212000 + }, + { + "id": 15835244, + "date": 1392940000 + }, + { + "id": 23646077, + "date": 1393459000 + }, + { + "id": 38015510, + "date": 1393632000 + }, + { + "id": 44634663, + "date": 1399334000 + }, + { + "id": 46145305, + "date": 1400198000 + }, + { + "id": 54845238, + "date": 1411257000 + }, + { + "id": 63263518, + "date": 1414454000 + }, + { + "id": 101260938, + "date": 1425600000 + }, + { + "id": 101323197, + "date": 1426204000 + }, + { + "id": 103151531, + "date": 1433376000 + }, + { + "id": 103258382, + "date": 1432771000 + }, + { + "id": 109393468, + "date": 1439078000 + }, + { + "id": 111220210, + "date": 1429574000 + }, + { + "id": 112594714, + "date": 1439683000 + }, + { + "id": 116812045, + "date": 1437696000 + }, + { + "id": 122600695, + "date": 1437782000 + }, + { + "id": 124872445, + "date": 1439856000 + }, + { + "id": 125828524, + "date": 1444003000 + }, + { + "id": 130029930, + "date": 1441324000 + }, + { + "id": 133909606, + "date": 1444176000 + }, + { + "id": 143445125, + "date": 1448928000 + }, + { + "id": 148670295, + "date": 1452211000 + }, + { + "id": 152079341, + "date": 1453420000 + }, + { + "id": 157242073, + "date": 1446768000 + }, + { + "id": 171295414, + "date": 1457481000 + }, + { + "id": 181783990, + "date": 1460246000 + }, + { + "id": 222021233, + "date": 1465344000 + }, + { + "id": 225034354, + "date": 1466208000 + }, + { + "id": 278941742, + "date": 1473465000 + }, + { + "id": 285253072, + "date": 1476835000 + }, + { + "id": 294851037, + "date": 1479600000 + }, + { + "id": 297621225, + "date": 1481846000 + }, + { + "id": 328594461, + "date": 1482969000 + }, + { + "id": 337808429, + "date": 1487707000 + }, + { + "id": 341546272, + "date": 1487782000 + }, + { + "id": 352940995, + "date": 1487894000 + }, + { + "id": 369669043, + "date": 1490918000 + }, + { + "id": 400169472, + "date": 1501459000 + }, + { + "id": 616816630, + "date": 1529625600 + }, + { + "id": 681896077, + "date": 1532821500 + }, + { + "id": 727572658, + "date": 1543708800 + }, + { + "id": 796147074, + "date": 1541371800 + }, + { + "id": 925078064, + "date": 1563290000 + }, + { + "id": 928636984, + "date": 1581513420 + }, + { + "id": 1054883348, + "date": 1585674420 + }, + { + "id": 1057704545, + "date": 1580393640 + }, + { + "id": 1145856008, + "date": 1586342040 + }, + { + "id": 1227964864, + "date": 1596127860 + }, + { + "id": 1382531194, + "date": 1600188120 + }, + { + "id": 1658586909, + "date": 1613148540 + }, + { + "id": 1660971491, + "date": 1613329440 + }, + { + "id": 1692464211, + "date": 1615402500 + }, + { + "id": 1719536397, + "date": 1619293500 + }, + { + "id": 1721844091, + "date": 1620224820 + }, + { + "id": 1772991138, + "date": 1617540360 + }, + { + "id": 1807942741, + "date": 1625520300 + }, + { + "id": 1893429550, + "date": 1622040000 + }, + { + "id": 1972424006, + "date": 1631669400 + }, + { + "id": 1974255900, + "date": 1634000000 + }, + { + "id": 2030606431, + "date": 1631992680 + }, + { + "id": 2041327411, + "date": 1631989620 + }, + { + "id": 2078711279, + "date": 1634321820 + }, + { + "id": 2104178931, + "date": 1638353220 + }, + { + "id": 2120496865, + "date": 1636714020 + }, + { + "id": 2123596685, + "date": 1636503180 + }, + { + "id": 2138472342, + "date": 1637590800 + }, + { + "id": 3318845111, + "date": 1618028800 + }, + { + "id": 4317845111, + "date": 1620028800 + }, + { + "id": 5162494923, + "date": 1652449800 + }, + { + "id": 5186883095, + "date": 1648764360 + }, + { + "id": 5304951856, + "date": 1656718440 + }, + { + "id": 5317829834, + "date": 1653152820 + }, + { + "id": 5318092331, + "date": 1652024220 + }, + { + "id": 5336336790, + "date": 1646368100 + }, + { + "id": 5362593868, + "date": 1652024520 + }, + { + "id": 5387234031, + "date": 1662137700 + }, + { + "id": 5396587273, + "date": 1648014800 + }, + { + "id": 5409444610, + "date": 1659025020 + }, + { + "id": 5416026704, + "date": 1660925460 + }, + { + "id": 5465223076, + "date": 1661710860 + }, + { + "id": 5480654757, + "date": 1660926300 + }, + { + "id": 5499934702, + "date": 1662130740 + }, + { + "id": 5513192189, + "date": 1659626400 + }, + { + "id": 5522237606, + "date": 1654167240 + }, + { + "id": 5537251684, + "date": 1664269800 + }, + { + "id": 5559167331, + "date": 1656718560 + }, + { + "id": 5568348673, + "date": 1654642200 + }, + { + "id": 5591759222, + "date": 1659025500 + }, + { + "id": 5608562550, + "date": 1664012820 + }, + { + "id": 5614111200, + "date": 1661780160 + }, + { + "id": 5666819340, + "date": 1664112240 + }, + { + "id": 5684254605, + "date": 1662134040 + }, + { + "id": 5684689868, + "date": 1661304720 + }, + { + "id": 5707112959, + "date": 1663803300 + }, + { + "id": 5756095415, + "date": 1660925940 + }, + { + "id": 5772670706, + "date": 1661539140 + }, + { + "id": 5778063231, + "date": 1667477640 + }, + { + "id": 5802242180, + "date": 1671821040 + }, + { + "id": 5853442730, + "date": 1674866100 + }, + { + "id": 5859878513, + "date": 1673117760 + }, + { + "id": 5885964106, + "date": 1671081840 + }, + { + "id": 5982648124, + "date": 1686941700 + }, + { + "id": 6020888206, + "date": 1675534800 + }, + { + "id": 6032606998, + "date": 1686998640 + }, + { + "id": 6057123350, + "date": 1676198350 + }, + { + "id": 6058560984, + "date": 1686907980 + }, + { + "id": 6101607245, + "date": 1686830760 + }, + { + "id": 6108011341, + "date": 1681032060 + }, + { + "id": 6132325730, + "date": 1692033840 + }, + { + "id": 6182056052, + "date": 1687870740 + }, + { + "id": 6279839148, + "date": 1688399160 + }, + { + "id": 6306077724, + "date": 1692442920 + }, + { + "id": 6321562426, + "date": 1688486760 + }, + { + "id": 6364973680, + "date": 1696349340 + }, + { + "id": 6386727079, + "date": 1691696880 + }, + { + "id": 6429580803, + "date": 1692082680 + }, + { + "id": 6527226055, + "date": 1690289160 + }, + { + "id": 6813121418, + "date": 1698489600 + }, + { + "id": 6865576492, + "date": 1699052400 + }, + { + "id": 6925870357, + "date": 1701192327 + }, + { + "id": 7000000000, + "date": 1711889200 + } +] \ No newline at end of file diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index 8df9a9a02b..1cdd8067ac 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -325,6 +325,7 @@ import tw.nekomimi.nekogram.utils.UIUtil; import xyz.nextalone.nagram.NaConfig; import xyz.nextalone.nagram.helper.MessageHelper; +import xyz.nextalone.nagram.helper.ProfileDateHelper; public class ProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate, SharedMediaLayout.SharedMediaPreloaderDelegate, ImageUpdater.ImageUpdaterDelegate, SharedMediaLayout.Delegate { private final static int PHONE_OPTION_CALL = 0, @@ -9797,7 +9798,11 @@ private void updateProfileData(boolean reload) { int finalDc = dc; idTextView.setOnClickListener(v -> { BottomBuilder builder = new BottomBuilder(getParentActivity()); - builder.addTitle(finalId + ""); + if (finalId == userId) { + builder.addTitle(finalId + "", ProfileDateHelper.getUserTime(finalId)); + } else { + builder.addTitle(finalId + ""); + } builder.addItem(LocaleController.getString("Copy", R.string.Copy), R.drawable.msg_copy, __ -> { AlertUtil.copyAndAlert(finalId + ""); return Unit.INSTANCE; diff --git a/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/ProfileDateHelper.kt b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/ProfileDateHelper.kt new file mode 100644 index 0000000000..96229f7a07 --- /dev/null +++ b/TMessagesProj/src/main/kotlin/xyz/nextalone/nagram/helper/ProfileDateHelper.kt @@ -0,0 +1,70 @@ +package xyz.nextalone.nagram.helper + +import com.google.android.exoplayer2.util.Util +import com.google.common.base.Charsets +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import org.telegram.messenger.ApplicationLoader +import org.telegram.messenger.FileLog +import org.telegram.messenger.LocaleController +import org.telegram.messenger.R +import java.util.Date + +object ProfileDateHelper { + + private const val JSON_FILE = "id_date.json" + private var profileDateDataList: List? = null + + private fun loadDate() { + if (profileDateDataList != null) { + return + } + try { + val ctx = ApplicationLoader.applicationContext + val `in` = ctx.assets.open(JSON_FILE) + val json = String(Util.toByteArray(`in`), Charsets.UTF_8) + profileDateDataList = Gson().fromJson(json, object : TypeToken?>() {}.type) + `in`.close() + } catch (e: Exception) { + FileLog.e(e) + } + } + + @JvmStatic + fun getUserTime(prefix: String, date: Long): String { + val st = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(Date(date)), LocaleController.getInstance().formatterDay.format(Date(date))) + return "$prefix $st" + } + + @JvmStatic + fun getUserTime(userId: Long): String { + if (profileDateDataList == null) { + loadDate() + } + if (profileDateDataList == null) { + return "unknown" + } + for (i in 1 until profileDateDataList!!.size) { + val data1 = profileDateDataList!![i - 1] + val data2 = profileDateDataList!![i] + if (userId >= data1.id && userId <= data2.id) { + val idx: Long = userId - data1.id + val idxRange: Long = data2.id - data1.id + val t = idx * 1.0 / idxRange + val date1: Long = data1.date + val date2: Long = data2.date + val date = (date1 + t * (date2 - date1)) * 1000.0 + val dateLong = Math.round(date) + return getUserTime("~", dateLong) + } + } + return if (userId <= 1000000) { + getUserTime("=", 1380326400000L) + } else getUserTime(">", 1711889200000L) + } + + class ProfileDateData { + var id: Long = 0 + var date: Long = 0 + } +} \ No newline at end of file