Skip to content

Commit

Permalink
feat: prepare in-app update
Browse files Browse the repository at this point in the history
Signed-off-by: Next Alone <[email protected]>
  • Loading branch information
NextAlone committed Dec 9, 2023
1 parent 90543da commit 20b8d64
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5311,8 +5311,8 @@ void setOpenProgress(float progress) {
contentView.addView(rightSlidingDialogContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

PrivacyUtils.postCheckAll(getParentActivity(), currentAccount);
// if (new Random().nextInt(100) < 50)
// UpdateUtils.postCheckFollowChannel(getParentActivity(), currentAccount);
if (new Random().nextInt(100) < 50)
UpdateUtils.postCheckFollowChannel(getParentActivity(), currentAccount);

contentView.addView(dialogStoriesCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, DialogStoriesCell.HEIGHT_IN_DP));
updateStoriesVisibility(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2621,7 +2621,7 @@ private boolean handleIntent(Intent intent, boolean isNew, boolean restore, bool
open_settings = 1;
}
} else if (url.startsWith("tg:upgrade") || url.startsWith("tg://upgrade") || url.startsWith("tg:update") || url.startsWith("tg://update")) {
// checkAppUpdate(true);
checkAppUpdate(true);
} else if ((url.startsWith("tg:search") || url.startsWith("tg://search"))) {
url = url.replace("tg:search", "tg://telegram.org").replace("tg://search", "tg://telegram.org");
data = Uri.parse(url);
Expand Down Expand Up @@ -5275,9 +5275,9 @@ public void checkAppUpdate(boolean force) {
if (force) {
if (!error) {
// if (!BuildConfig.isPlay) {
// showBulletin(factory -> factory.createErrorBulletin(LocaleController.getString("VersionUpdateNoUpdate", R.string.VersionUpdateNoUpdate)));
showBulletin(factory -> factory.createErrorBulletin(LocaleController.getString("VersionUpdateNoUpdate", R.string.VersionUpdateNoUpdate)));
// } else {
showBulletin(factory -> factory.createSimpleBulletin(R.raw.chats_infotip, LocaleController.getString("NoUpdateAvailablePlay", R.string.NoUpdateAvailablePlay), LocaleController.getString("NoUpdateAvailablePlayDelay", R.string.NoUpdateAvailablePlayDelay)));
// showBulletin(factory -> factory.createSimpleBulletin(R.raw.chats_infotip, LocaleController.getString("NoUpdateAvailablePlay", R.string.NoUpdateAvailablePlay), LocaleController.getString("NoUpdateAvailablePlayDelay", R.string.NoUpdateAvailablePlayDelay)));
// }
} else {
AlertsCreator.createSimpleAlert(this, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error).show();
Expand Down Expand Up @@ -6033,7 +6033,7 @@ protected void onResume() {
} else if (SharedConfig.pendingAppUpdate != null && SharedConfig.pendingAppUpdate.can_not_skip) {
showUpdateActivity(UserConfig.selectedAccount, SharedConfig.pendingAppUpdate, true);
}
// checkAppUpdate(false);
checkAppUpdate(false);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
ApplicationLoader.canDrawOverlays = Settings.canDrawOverlays(this);
Expand Down
36 changes: 18 additions & 18 deletions TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3545,19 +3545,19 @@ public void openExceptions() {
currentUpdateChannel = Defines.stableChannel;
currentChannel += LocaleController.getString("AutoCheckUpdateStable", R.string.AutoCheckUpdateStable);
break;
case Defines.ciChannel:
currentUpdateChannel = Defines.ciChannel;
currentChannel += LocaleController.getString("AutoCheckUpdatePreview", R.string.AutoCheckUpdatePreview);
break;
// case Defines.ciChannel:
// currentUpdateChannel = Defines.ciChannel;
// currentChannel += LocaleController.getString("AutoCheckUpdatePreview", R.string.AutoCheckUpdatePreview);
// break;
default:
if (BuildConfig.VERSION_NAME.contains("preview")) {
currentUpdateChannel = Defines.ciChannel;
currentChannel += LocaleController.getString("AutoCheckUpdatePreview", R.string.AutoCheckUpdatePreview);

} else {
currentUpdateChannel = Defines.stableChannel;
currentChannel += LocaleController.getString("AutoCheckUpdateStable", R.string.AutoCheckUpdateStable);
}
// if (BuildConfig.VERSION_NAME.contains("preview")) {
// currentUpdateChannel = Defines.ciChannel;
// currentChannel += LocaleController.getString("AutoCheckUpdatePreview", R.string.AutoCheckUpdatePreview);
//
// } else {
currentUpdateChannel = Defines.stableChannel;
currentChannel += LocaleController.getString("AutoCheckUpdateStable", R.string.AutoCheckUpdateStable);
// }
}

builder.addItem(LocaleController.getString("AutoCheckUpdateSwitch", R.string.AutoCheckUpdateSwitch) + currentChannel, R.drawable.baseline_system_update_24, (it) -> {
Expand All @@ -3573,11 +3573,11 @@ public void openExceptions() {
switchBuilder.doRadioCheck(radioButtonCell);
return Unit.INSTANCE;
});
switchBuilder.addRadioItem(LocaleController.getString("AutoCheckUpdatePreview", R.string.AutoCheckUpdatePreview), currentUpdateChannel == Defines.ciChannel, (radioButtonCell) -> {
ConfigManager.putInt(Defines.updateChannel, Defines.ciChannel);
switchBuilder.doRadioCheck(radioButtonCell);
return Unit.INSTANCE;
});
// switchBuilder.addRadioItem(LocaleController.getString("AutoCheckUpdatePreview", R.string.AutoCheckUpdatePreview), currentUpdateChannel == Defines.ciChannel, (radioButtonCell) -> {
// ConfigManager.putInt(Defines.updateChannel, Defines.ciChannel);
// switchBuilder.doRadioCheck(radioButtonCell);
// return Unit.INSTANCE;
// });
showDialog(switchBuilder.create());
return Unit.INSTANCE;
});
Expand Down Expand Up @@ -3679,7 +3679,7 @@ public boolean onItemClick(View view, int position) {
} else if (which == 8) {
SharedConfig.toggleRoundCamera16to9();
} else if (which == 9) {
// ((LaunchActivity) getParentActivity()).checkAppUpdate(true);
((LaunchActivity) getParentActivity()).checkAppUpdate(true);
} else if (which == 10) {
getMessagesStorage().readAllDialogs(-1);
} else if (which == 11) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2666,7 +2666,7 @@ private void createUnsupportedContainer() {
buttonTextView.setOnClickListener(v -> {
if (ApplicationLoader.isStandaloneBuild()) {
if (LaunchActivity.instance != null) {
// LaunchActivity.instance.checkAppUpdate(true);
LaunchActivity.instance.checkAppUpdate(true);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ object Defines {
const val updateChannel = "updateChannel"
const val stableChannel = 1
const val disableAutoUpdate = 0
const val ciChannel = 2
// const val ciChannel = 2
const val updateChannelSkip = "updateChannelSkip"

// Tab Menu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ import java.util.Arrays

object UpdateUtils {

private const val channelUsername = "NullgramClient"
private const val channelUsername = "Nnngram"

private val originalChannelUsername = String(Base64.decode("TnVsbGdyYW1DbGllbnQK", Base64.DEFAULT))
private val originalChannelUsername = String(Base64.decode("Tm5uZ3JhbQo=", Base64.DEFAULT))

@JvmStatic
fun postCheckFollowChannel(ctx: Context, currentAccount: Int) = CoroutineScope(Dispatchers.IO).launch {
Expand Down Expand Up @@ -122,7 +122,7 @@ object UpdateUtils {
return
}

if (BuildConfig.APPLICATION_ID != Arrays.toString(Base64.decode("dG9wLnF3cTIzMzMubnVsbGdyYW0=", Base64.DEFAULT))) {
if (BuildConfig.APPLICATION_ID != Arrays.toString(Base64.decode("eHl6Lm5leHRhbG9uZS5ubm5ncmFtCg==", Base64.DEFAULT))) {
ApplicationLoader.applicationHandler.post {
val messagesCollector = MessagesController.getInstance(currentAccount)
val userConfig = UserConfig.getInstance(currentAccount)
Expand Down Expand Up @@ -150,22 +150,18 @@ object UpdateUtils {
}

private const val maxReadCount = 50
private const val stableMetadataChannelID: Long = 1514826137
private const val stableMetadataChannelName = "NullgramMetaData"
private const val previewMetadataChannelID: Long = 1524514483
private const val previewMetadataChannelName = "PreviewMetaData"
private const val stableChannelAPKsID: Long = 1645976613
private const val stableChannelAPKsName = "NullgramAPKs"
private const val previewChannelAPKsID: Long = 1714986438
private const val previewChannelAPKsName = "NullgramCI"
// private const val stableMetadataChannelID: Long = 1514826137
// private const val stableMetadataChannelName = "NullgramMetaData"
private const val previewMetadataChannelID: Long = 2135305446
private const val previewMetadataChannelName = "NnngramMetaData"
// private const val stableChannelAPKsID: Long = 1645976613
// private const val stableChannelAPKsName = "NullgramAPKs"
private const val previewChannelAPKsID: Long = 1848519901
private const val previewChannelAPKsName = "Nnngram"

@JvmStatic
fun retrieveUpdateMetadata(callback: (UpdateMetadata?, Boolean) -> Unit) {
val (metadataChannelID, metadataChannelName) = when (ConfigManager.getIntOrDefault(Defines.updateChannel, -1)) {
Defines.stableChannel -> stableMetadataChannelID to stableMetadataChannelName
Defines.ciChannel -> previewMetadataChannelID to previewMetadataChannelName
else -> if (BuildConfig.VERSION_NAME.contains("preview")) previewMetadataChannelID to previewMetadataChannelName else stableMetadataChannelID to stableMetadataChannelName
}
val (metadataChannelID, metadataChannelName) = previewMetadataChannelID to previewMetadataChannelName
val localVersionCode = BuildConfig.VERSION_CODE
val accountInstance = AccountInstance.getInstance(UserConfig.selectedAccount)
TLRPC.TL_messages_getHistory().apply {
Expand Down Expand Up @@ -285,11 +281,7 @@ object UpdateUtils {
@JvmStatic
fun checkUpdate(callback: (TLRPC.TL_help_appUpdate?, Boolean) -> Unit) {
if (!UserConfig.getInstance(UserConfig.selectedAccount).isClientActivated) return
val (apksChannelID, apksChannelName) = when (ConfigManager.getIntOrDefault(Defines.updateChannel, -1)) {
Defines.stableChannel -> stableChannelAPKsID to stableChannelAPKsName
Defines.ciChannel -> previewChannelAPKsID to previewChannelAPKsName
else -> if (BuildConfig.VERSION_NAME.contains("preview")) previewChannelAPKsID to previewChannelAPKsName else stableChannelAPKsID to stableChannelAPKsName
}
val (apksChannelID, apksChannelName) = previewChannelAPKsID to previewChannelAPKsName
val accountInstance = AccountInstance.getInstance(UserConfig.selectedAccount)
retrieveUpdateMetadata { metadata, error ->
if (metadata == null) {
Expand Down

0 comments on commit 20b8d64

Please sign in to comment.