aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/services/UpdateService.java15
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationsActivity.java20
-rw-r--r--src/main/java/de/pixart/messenger/ui/UpdaterActivity.java49
-rw-r--r--src/main/java/de/pixart/messenger/ui/XmppActivity.java7
4 files changed, 40 insertions, 51 deletions
diff --git a/src/main/java/de/pixart/messenger/services/UpdateService.java b/src/main/java/de/pixart/messenger/services/UpdateService.java
index bf5242939..1d797324e 100644
--- a/src/main/java/de/pixart/messenger/services/UpdateService.java
+++ b/src/main/java/de/pixart/messenger/services/UpdateService.java
@@ -42,7 +42,7 @@ public class UpdateService extends AsyncTask<String, Object, UpdateService.Wrapp
@Override
protected Wrapper doInBackground(String... params) {
- String jsonString = "";
+ StringBuilder jsonString = new StringBuilder();
boolean UpdateAvailable = false;
boolean showNoUpdateToast = false;
boolean isError = false;
@@ -66,9 +66,8 @@ public class UpdateService extends AsyncTask<String, Object, UpdateService.Wrapp
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
- jsonString += line;
+ jsonString.append(line);
}
-
} catch (Exception e) {
e.printStackTrace();
isError = true;
@@ -79,7 +78,7 @@ public class UpdateService extends AsyncTask<String, Object, UpdateService.Wrapp
}
try {
- JSONObject json = new JSONObject(jsonString);
+ JSONObject json = new JSONObject(jsonString.toString());
if (json.getBoolean("success") && json.has("latestVersion") && json.has("appURI") && json.has("filesize")) {
String version = json.getString("latestVersion");
String ownVersion = BuildConfig.VERSION_NAME;
@@ -198,9 +197,9 @@ public class UpdateService extends AsyncTask<String, Object, UpdateService.Wrapp
return 0;
}
- public class Wrapper {
- public boolean UpdateAvailable = false;
- public boolean NoUpdate = false;
- public boolean isError = false;
+ class Wrapper {
+ boolean UpdateAvailable = false;
+ boolean NoUpdate = false;
+ boolean isError = false;
}
} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java
index 1f2c68159..932ab452b 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java
@@ -95,8 +95,6 @@ import de.pixart.messenger.xmpp.OnUpdateBlocklist;
import de.pixart.messenger.xmpp.chatstate.ChatState;
import rocks.xmpp.addr.Jid;
-import static de.pixart.messenger.services.XmppConnectionService.FDroid;
-import static de.pixart.messenger.services.XmppConnectionService.PlayStore;
import static de.pixart.messenger.ui.ConversationFragment.REQUEST_DECRYPT_PGP;
import static de.pixart.messenger.ui.SettingsActivity.USE_BUNDLED_EMOJIS;
@@ -596,15 +594,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
return true;
case R.id.action_check_updates:
if (xmppConnectionService.hasInternetConnection()) {
- if (!installFromUnknownSourceAllowed() && xmppConnectionService.installedFrom() == null) {
- openInstallFromUnknownSourcesDialogIfNeeded();
- } else if (!installFromUnknownSourceAllowed() && (xmppConnectionService.installedFrom() != null && !xmppConnectionService.installedFrom().equalsIgnoreCase(PlayStore))) {
- openInstallFromUnknownSourcesDialogIfNeeded();
- } else {
- UpdateService task = new UpdateService(this, xmppConnectionService.installedFrom(), xmppConnectionService);
- task.executeOnExecutor(UpdateService.THREAD_POOL_EXECUTOR, "true");
- Log.d(Config.LOGTAG, "AppUpdater started");
- }
+ openInstallFromUnknownSourcesDialogIfNeeded();
} else {
Toast.makeText(this, R.string.account_status_no_internet, Toast.LENGTH_LONG).show();
}
@@ -987,18 +977,14 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
editor.putLong("lastUpdateTime", lastUpdateTime);
editor.apply();
Log.d(Config.LOGTAG, "AppUpdater: CurrentTime: " + lastUpdateTime);
- if (!installFromUnknownSourceAllowed() && Store == null) {
+ if (Store == null) {
+ Log.d(Config.LOGTAG, "AppUpdater started");
openInstallFromUnknownSourcesDialogIfNeeded();
- } else if (Store != null && (Store.equalsIgnoreCase(PlayStore) || Store.equalsIgnoreCase(FDroid))) {
- Log.d(Config.LOGTAG, "AppUpdater aborted because app store is " + Store);
- } else {
UpdateService task = new UpdateService(this, Store, xmppConnectionService);
task.executeOnExecutor(UpdateService.THREAD_POOL_EXECUTOR, "false");
- Log.d(Config.LOGTAG, "AppUpdater started");
}
} else {
Log.d(Config.LOGTAG, "AppUpdater stopped");
- return;
}
}
} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java
index 15d680a42..fbed2daeb 100644
--- a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java
@@ -3,7 +3,6 @@ package de.pixart.messenger.ui;
import android.Manifest;
import android.app.ProgressDialog;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
@@ -157,8 +156,7 @@ public class UpdaterActivity extends XmppActivity {
}
} else {
Toast.makeText(getApplicationContext(), getText(R.string.download_started), Toast.LENGTH_LONG).show();
- downloadTask = new DownloadTask(UpdaterActivity.this) {
- };
+ downloadTask = new DownloadTask(UpdaterActivity.this);
downloadTask.execute(appURI);
}
} else {
@@ -166,13 +164,18 @@ public class UpdaterActivity extends XmppActivity {
}
})
.setNeutralButton(R.string.changelog, (dialog, id) -> {
- Uri uri = Uri.parse(Config.CHANGELOG_URL); // missing 'http://' will cause crashed
- Intent intent = new Intent(Intent.ACTION_VIEW, uri);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(intent);
- overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
- //restart updater to show dialog again after coming back after opening changelog
- recreate();
+ Uri uri = Uri.parse(Config.CHANGELOG_URL); // missing 'http://' will cause crash
+ try {
+ Intent intent = new Intent(Intent.ACTION_VIEW, uri);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(intent);
+ overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ //restart updater to show dialog again after coming back after opening changelog
+ recreate();
+ }
})
.setNegativeButton(R.string.remind_later, (dialog, id) -> {
// User cancelled the dialog
@@ -212,8 +215,8 @@ public class UpdaterActivity extends XmppActivity {
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
- for (int i = 0; i < info.length; i++) {
- if (info[i].getState() == NetworkInfo.State.CONNECTED) {
+ for (NetworkInfo anInfo : info) {
+ if (anInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
@@ -247,17 +250,14 @@ public class UpdaterActivity extends XmppActivity {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.cancel_update)
.setCancelable(false)
- .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- if (downloadTask != null && !downloadTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
- downloadTask.cancel(true);
- }
- if (mProgressDialog.isShowing()) {
- mProgressDialog.dismiss();
- }
- UpdaterActivity.this.finish();
+ .setPositiveButton(R.string.yes, (dialog, id) -> {
+ if (downloadTask != null && !downloadTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
+ downloadTask.cancel(true);
}
+ if (mProgressDialog.isShowing()) {
+ mProgressDialog.dismiss();
+ }
+ UpdaterActivity.this.finish();
})
.setNegativeButton(R.string.no, (dialog, id) -> dialog.cancel());
AlertDialog alert = builder.create();
@@ -286,13 +286,13 @@ public class UpdaterActivity extends XmppActivity {
File dir = new File(FileBackend.getAppUpdateDirectory());
File file = new File(dir, FileName);
+ XmppConnectionService xmppConnectionService;
private Context context;
private PowerManager.WakeLock mWakeLock;
private long startTime = 0;
- XmppConnectionService xmppConnectionService;
private boolean mUseTor;
- public DownloadTask(Context context) {
+ DownloadTask(Context context) {
this.context = context;
}
@@ -409,6 +409,5 @@ public class UpdaterActivity extends XmppActivity {
UpdaterActivity.this.finish();
}
}
-
}
}
diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
index dcf3afed4..0a0f5da77 100644
--- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
@@ -74,6 +74,7 @@ import de.pixart.messenger.entities.Message;
import de.pixart.messenger.entities.Presences;
import de.pixart.messenger.services.AvatarService;
import de.pixart.messenger.services.BarcodeProvider;
+import de.pixart.messenger.services.UpdateService;
import de.pixart.messenger.services.XmppConnectionService;
import de.pixart.messenger.services.XmppConnectionService.XmppConnectionBinder;
import de.pixart.messenger.ui.util.PresenceSelector;
@@ -1236,7 +1237,7 @@ public abstract class XmppActivity extends ActionBarActivity {
}
protected void openInstallFromUnknownSourcesDialogIfNeeded() {
- if (!installFromUnknownSourceAllowed()) {
+ if (!installFromUnknownSourceAllowed() && xmppConnectionService.installedFrom() == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.install_from_unknown_sources_disabled);
builder.setMessage(R.string.install_from_unknown_sources_disabled_dialog);
@@ -1254,6 +1255,10 @@ public abstract class XmppActivity extends ActionBarActivity {
startActivityForResult(intent, REQUEST_UNKNOWN_SOURCE_OP);
} catch (ActivityNotFoundException e) {
Toast.makeText(XmppActivity.this, R.string.device_does_not_support_battery_op, Toast.LENGTH_SHORT).show();
+ } finally {
+ UpdateService task = new UpdateService(this, xmppConnectionService.installedFrom(), xmppConnectionService);
+ task.executeOnExecutor(UpdateService.THREAD_POOL_EXECUTOR, "true");
+ Log.d(Config.LOGTAG, "AppUpdater started");
}
});
builder.create().show();