fix update

This commit is contained in:
vivabelarus 2022-12-17 17:17:59 +04:00
parent 007d6037f5
commit d182362a60
No known key found for this signature in database
GPG key ID: D8D8542F5B70C314
3 changed files with 38 additions and 8 deletions

View file

@ -2,6 +2,7 @@ package org.telegram.messenger.partisan;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.telegram.messenger.MessageObject;
import org.telegram.tgnet.TLRPC;
import java.util.ArrayList;
@ -11,6 +12,7 @@ public class UpdateData {
public AppVersion originalVersion;
public boolean canNotSkip;
public String text;
public TLRPC.Message message;
public TLRPC.Document document;
public TLRPC.Document sticker;
public ArrayList<TLRPC.MessageEntity> entities = new ArrayList<>();

View file

@ -37,6 +37,7 @@ class UpdateMessageParser {
currentUpdate = new UpdateData();
currentUpdate.accountNum = currentAccount;
currentUpdate.message = message.replyMessageObject.messageOwner;
currentUpdate.document = message.replyMessageObject.getDocument();
currentMessage = message;

View file

@ -72,6 +72,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.arch.core.util.Function;
import androidx.collection.LongSparseArray;
import androidx.core.app.ActivityCompat;
import androidx.core.content.pm.ShortcutInfoCompat;
import androidx.core.content.pm.ShortcutManagerCompat;
@ -1415,6 +1416,11 @@ public class LaunchActivity extends BasePermissionsActivity implements INavigati
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.fileLoaded);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.fileLoadProgressChanged);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.fileLoadFailed);
if (SharedConfig.pendingPtgAppUpdate != null && getUpdateAccountNum() != currentAccount) {
NotificationCenter.getInstance(getUpdateAccountNum()).removeObserver(this, NotificationCenter.fileLoadProgressChanged);
NotificationCenter.getInstance(getUpdateAccountNum()).removeObserver(this, NotificationCenter.fileLoaded);
NotificationCenter.getInstance(getUpdateAccountNum()).removeObserver(this, NotificationCenter.fileLoadFailed);
}
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.historyImportProgressChanged);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.groupCallUpdated);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.stickersImportComplete);
@ -1434,6 +1440,12 @@ public class LaunchActivity extends BasePermissionsActivity implements INavigati
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.fileLoaded);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.fileLoadProgressChanged);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.fileLoadFailed);
if (updateLayoutIcon != null && updateLayoutIcon.getIcon() == MediaActionDrawable.ICON_CANCEL
&& SharedConfig.pendingPtgAppUpdate != null && getUpdateAccountNum() != currentAccount) {
NotificationCenter.getInstance(getUpdateAccountNum()).addObserver(this, NotificationCenter.fileLoaded);
NotificationCenter.getInstance(getUpdateAccountNum()).addObserver(this, NotificationCenter.fileLoadProgressChanged);
NotificationCenter.getInstance(getUpdateAccountNum()).addObserver(this, NotificationCenter.fileLoadFailed);
}
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.historyImportProgressChanged);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.groupCallUpdated);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.stickersImportComplete);
@ -4642,6 +4654,11 @@ public class LaunchActivity extends BasePermissionsActivity implements INavigati
if (!SharedConfig.isAppUpdateAvailable()) {
return;
}
if (getUpdateAccountNum() != currentAccount) {
NotificationCenter.getInstance(getUpdateAccountNum()).removeObserver(this, NotificationCenter.fileLoaded);
NotificationCenter.getInstance(getUpdateAccountNum()).removeObserver(this, NotificationCenter.fileLoadProgressChanged);
NotificationCenter.getInstance(getUpdateAccountNum()).removeObserver(this, NotificationCenter.fileLoadFailed);
}
if (updateLayoutIcon.getIcon() == MediaActionDrawable.ICON_DOWNLOAD) {
startUpdateDownloading();
} else if (updateLayoutIcon.getIcon() == MediaActionDrawable.ICON_CANCEL) {
@ -4684,14 +4701,14 @@ public class LaunchActivity extends BasePermissionsActivity implements INavigati
createUpdateUI();
updateSizeTextView.setText(AndroidUtilities.formatFileSize(SharedConfig.pendingPtgAppUpdate.document.size));
String fileName = FileLoader.getAttachFileName(SharedConfig.pendingPtgAppUpdate.document);
File path = FileLoader.getInstance(currentAccount).getPathToAttach(SharedConfig.pendingPtgAppUpdate.document, true);
File path = FileLoader.getInstance(getUpdateAccountNum()).getPathToAttach(SharedConfig.pendingPtgAppUpdate.document, true);
boolean showSize;
if (path.exists()) {
updateLayoutIcon.setIcon(MediaActionDrawable.ICON_UPDATE, true, false);
updateTextView.setText(LocaleController.getString("AppUpdateNow", R.string.AppUpdateNow));
showSize = false;
} else {
if (FileLoader.getInstance(currentAccount).isLoadingFile(fileName)) {
if (FileLoader.getInstance(getUpdateAccountNum()).isLoadingFile(fileName)) {
updateLayoutIcon.setIcon(MediaActionDrawable.ICON_CANCEL, true, false);
updateLayoutIcon.setProgress(0, false);
Float p = ImageLoader.getInstance().getFileProgress(fileName);
@ -5087,6 +5104,11 @@ public class LaunchActivity extends BasePermissionsActivity implements INavigati
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.needShowPlayServicesAlert);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.fileLoaded);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.fileLoadProgressChanged);
if (SharedConfig.pendingPtgAppUpdate != null && getUpdateAccountNum() != currentAccount) {
NotificationCenter.getInstance(getUpdateAccountNum()).removeObserver(this, NotificationCenter.fileLoaded);
NotificationCenter.getInstance(getUpdateAccountNum()).removeObserver(this, NotificationCenter.fileLoadProgressChanged);
NotificationCenter.getInstance(getUpdateAccountNum()).removeObserver(this, NotificationCenter.fileLoadFailed);
}
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.fileLoadFailed);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.historyImportProgressChanged);
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.groupCallUpdated);
@ -6561,23 +6583,28 @@ public class LaunchActivity extends BasePermissionsActivity implements INavigati
}
private void startUpdateDownloading() {
if (SharedConfig.pendingPtgAppUpdate.accountNum != currentAccount) {
if (getUpdateAccountNum() != currentAccount) {
UpdateChecker.checkUpdate(currentAccount, (updateFounded, data) -> {
if (updateFounded) {
SharedConfig.pendingPtgAppUpdate = data;
SharedConfig.saveConfig();
AndroidUtilities.runOnUIThread(() -> {
FileLoader.getInstance(currentAccount).loadFile(SharedConfig.pendingPtgAppUpdate.document, "update", FileLoader.PRIORITY_NORMAL, 1);
updateAppUpdateViews(true);
});
AndroidUtilities.runOnUIThread(this::startUpdateDownloading);
}
});
return;
}
FileLoader.getInstance(currentAccount).loadFile(SharedConfig.pendingPtgAppUpdate.document, "update", FileLoader.PRIORITY_NORMAL, 1);
MessageObject messageObject = new MessageObject(getUpdateAccountNum(), SharedConfig.pendingPtgAppUpdate.message, (LongSparseArray<TLRPC.User>) null, null, false, true);
FileLoader.getInstance(currentAccount).loadFile(SharedConfig.pendingPtgAppUpdate.document, messageObject, FileLoader.PRIORITY_NORMAL, 1);
updateAppUpdateViews(true);
}
private int getUpdateAccountNum() {
if (SharedConfig.pendingPtgAppUpdate == null) {
return -1;
}
return SharedConfig.pendingPtgAppUpdate.accountNum;
}
@Override
protected void onSaveInstanceState(Bundle outState) {
try {