From 71aa88f3702aa293b35832956f9d38481deff47c Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Fri, 3 Aug 2018 23:00:06 +0200 Subject: some changes in Updater --- .../pixart/messenger/services/UpdateService.java | 12 +++++------ .../messenger/services/XmppConnectionService.java | 19 ++++++++--------- .../pixart/messenger/ui/ConversationsActivity.java | 17 ++++++++------- .../de/pixart/messenger/ui/UpdaterActivity.java | 24 ++++++++++++++++++---- 4 files changed, 43 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/main/java/de/pixart/messenger/services/UpdateService.java b/src/main/java/de/pixart/messenger/services/UpdateService.java index 7e636b8e6..3b3829290 100644 --- a/src/main/java/de/pixart/messenger/services/UpdateService.java +++ b/src/main/java/de/pixart/messenger/services/UpdateService.java @@ -32,13 +32,13 @@ import static de.pixart.messenger.services.NotificationService.UPDATE_NOTIFICATI public class UpdateService extends AsyncTask { private boolean mUseTor; private Context context; - private boolean playstore; + private String store; public UpdateService() { } - public UpdateService(Context context, boolean PlayStore, XmppConnectionService mXmppConnectionService) { + public UpdateService(Context context, String Store, XmppConnectionService mXmppConnectionService) { this.context = context; - this.playstore = PlayStore; + this.store = Store; this.mUseTor = mXmppConnectionService.useTorToConnect(); } @@ -94,7 +94,7 @@ public class UpdateService extends AsyncTask= 1) { Log.d(Config.LOGTAG, "AppUpdater: Version " + ownVersion + " should be updated to " + version); UpdateAvailable = true; - showNotification(url, changelog, version, filesize, playstore); + showNotification(url, changelog, version, filesize, store); } else { Log.d(Config.LOGTAG, "AppUpdater: Version " + ownVersion + " is up to date"); UpdateAvailable = false; @@ -138,12 +138,12 @@ public class UpdateService extends AsyncTask Toast.makeText(this, resId, Toast.LENGTH_SHORT).show()); } - protected void AppUpdate(boolean PlayStore) { - if (PlayStore) { + protected void AppUpdate(String Store) { + if (Store == null) { return; } String PREFS_NAME = "UpdateTimeStamp"; @@ -954,10 +953,10 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio editor.putLong("lastUpdateTime", lastUpdateTime); editor.apply(); Log.d(Config.LOGTAG, "AppUpdater: CurrentTime: " + lastUpdateTime); - if (!installFromUnknownSourceAllowed() && !PlayStore) { + if (!installFromUnknownSourceAllowed() && !Store.equals(PlayStore)) { openInstallFromUnknownSourcesDialogIfNeeded(); } else { - UpdateService task = new UpdateService(this, PlayStore, xmppConnectionService); + UpdateService task = new UpdateService(this, Store, xmppConnectionService); task.executeOnExecutor(UpdateService.THREAD_POOL_EXECUTOR, "false"); Log.d(Config.LOGTAG, "AppUpdater started"); } diff --git a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java index 4832dc466..0c59b06c6 100644 --- a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java +++ b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java @@ -37,13 +37,15 @@ import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.utils.WakeLockHelper; import static de.pixart.messenger.http.HttpConnectionManager.getProxy; +import static de.pixart.messenger.services.XmppConnectionService.FDroid; +import static de.pixart.messenger.services.XmppConnectionService.PlayStore; public class UpdaterActivity extends XmppActivity { static final private String FileName = "update.apk"; String appURI = ""; String changelog = ""; Integer filesize = 0; - boolean playstore = false; + String store; ProgressDialog mProgressDialog; DownloadTask downloadTask; XmppConnectionService mXmppConnectionService; @@ -104,9 +106,9 @@ public class UpdaterActivity extends XmppActivity { UpdaterActivity.this.finish(); } try { - playstore = getIntent().getBooleanExtra("playstore", false); + store = getIntent().getStringExtra("store"); } catch (Exception e) { - playstore = false; + store = null; } //delete old downloaded localVersion files File dir = new File(FileBackend.getConversationsDirectory("Update", false)); @@ -129,7 +131,7 @@ public class UpdaterActivity extends XmppActivity { //ask for permissions on devices >= SDK 23 if (isStoragePermissionGranted() && isNetworkAvailable(getApplicationContext())) { //start downloading the file using the download manager - if (playstore) { + if (store.equals(PlayStore)) { Uri uri = Uri.parse("market://details?id=de.pixart.messenger"); Intent marketIntent = new Intent(Intent.ACTION_VIEW, uri); PackageManager manager = getApplicationContext().getPackageManager(); @@ -143,6 +145,20 @@ public class UpdaterActivity extends XmppActivity { startActivity(browserIntent); overridePendingTransition(R.animator.fade_in, R.animator.fade_out); } + } else if (store.equals(FDroid)) { + Uri uri = Uri.parse("https://f-droid.org/de/packages/de.pixart.messenger/"); + Intent marketIntent = new Intent(Intent.ACTION_VIEW, uri); + PackageManager manager = getApplicationContext().getPackageManager(); + List infos = manager.queryIntentActivities(marketIntent, 0); + if (infos.size() > 0) { + startActivity(marketIntent); + overridePendingTransition(R.animator.fade_in, R.animator.fade_out); + } else { + uri = Uri.parse("https://f-droid.org/de/packages/de.pixart.messenger/"); + Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri); + startActivity(browserIntent); + overridePendingTransition(R.animator.fade_in, R.animator.fade_out); + } } else { Toast.makeText(getApplicationContext(), getText(R.string.download_started), Toast.LENGTH_LONG).show(); downloadTask = new DownloadTask(UpdaterActivity.this) { -- cgit v1.2.3